2017-01-03 10:45:16 -08:00
using System ;
using System.Linq ;
using System.Threading ;
using System.Threading.Tasks ;
using MatterHackers.Agg.UI ;
using MatterHackers.GuiAutomation ;
using MatterHackers.MatterControl.PrinterCommunication ;
2017-03-09 12:44:20 -08:00
using MatterHackers.MatterControl.PrinterCommunication.Io ;
2017-01-03 10:45:16 -08:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2017-01-10 17:20:24 -08:00
using MatterHackers.PrinterEmulator ;
2017-02-01 10:20:50 -08:00
using MatterHackers.VectorMath ;
2017-01-03 10:45:16 -08:00
using NUnit.Framework ;
namespace MatterHackers.MatterControl.Tests.Automation
{
2017-06-03 18:33:48 -07:00
[TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
2017-01-03 10:45:16 -08:00
public class PrintingTests
{
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-01-03 10:45:16 -08:00
public async Task CompletingPrintTurnsoffHeat ( )
{
2017-06-02 20:29:03 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-01-03 10:45:16 -08:00
{
testRunner . WaitForName ( "Cancel Wizard Button" , 1 ) ;
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
2017-01-10 13:43:12 -08:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-01-03 10:45:16 -08:00
2017-06-02 19:39:29 -07:00
testRunner . SwitchToAdvancedSliceSettings ( ) ;
2017-01-03 10:45:16 -08:00
2017-06-05 09:27:30 -07:00
testRunner . ClickByName ( "Printer Tab" ) ;
testRunner . ClickByName ( "Custom G-Code Tab" ) ;
2017-09-22 23:28:00 -07:00
testRunner . ClickByName ( "End G-Code Field" ) ;
2017-01-10 13:43:12 -08:00
testRunner . Type ( "^a" ) ;
testRunner . Type ( "{BACKSPACE}" ) ;
testRunner . Type ( "G28" ) ;
2017-01-03 10:45:16 -08:00
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-01-03 10:45:16 -08:00
2017-06-05 09:27:30 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-01-03 10:45:16 -08:00
2017-06-02 17:04:02 -07:00
// Wait for print to finish
2017-06-02 21:20:56 -07:00
testRunner . WaitForPrintFinished ( ) ;
2017-06-02 17:04:02 -07:00
// Wait for expected temp
2017-09-17 21:08:16 -07:00
testRunner . Delay ( ( ) = > ApplicationController . Instance . ActivePrinter . Connection . GetActualHotendTemperature ( 0 ) < = 0 , 5 ) ;
Assert . Less ( ApplicationController . Instance . ActivePrinter . Connection . GetActualHotendTemperature ( 0 ) , 30 ) ;
2017-06-02 17:04:02 -07:00
// Wait for expected temp
2017-09-17 21:08:16 -07:00
testRunner . Delay ( ( ) = > ApplicationController . Instance . ActivePrinter . Connection . ActualBedTemperature < = 10 , 5 ) ;
Assert . Less ( ApplicationController . Instance . ActivePrinter . Connection . ActualBedTemperature , 10 ) ;
2017-01-10 13:43:12 -08:00
}
2017-01-03 10:45:16 -08:00
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-09-22 23:37:59 -07:00
} , maxTimeToRun : 70 ) ;
2017-01-03 10:45:16 -08:00
}
2017-01-10 17:20:24 -08:00
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-01-10 17:20:24 -08:00
public async Task PulseRequiresLevelingAndLevelingWorks ( )
{
2017-06-02 21:07:54 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-01-10 17:20:24 -08:00
{
testRunner . WaitForName ( "Cancel Wizard Button" , 1 ) ;
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( "Pulse" , "A-134" ) )
2017-01-10 17:20:24 -08:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
// close the finish setup window
testRunner . ClickByName ( "Cancel Button" ) ;
2017-06-02 19:39:29 -07:00
testRunner . SwitchToAdvancedSliceSettings ( ) ;
2017-01-10 17:20:24 -08:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "General Tab" ) ;
testRunner . ClickByName ( "Single Print Tab" ) ;
2017-09-14 14:47:08 -07:00
testRunner . ClickByName ( "Layer(s) To Pause Field" ) ;
2017-01-10 17:20:24 -08:00
testRunner . Type ( "2" ) ;
// switch to controls so we can see the heights
2017-06-13 13:22:22 -07:00
testRunner . SwitchToControlsTab ( ) ;
2017-01-10 17:20:24 -08:00
2017-08-09 14:35:28 -07:00
// run the leveling wizard (only 4 next as there is no heated bed
2017-01-10 17:20:24 -08:00
testRunner . ClickByName ( "Finish Setup Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
2017-01-19 12:35:33 -08:00
for ( int i = 0 ; i < 3 ; i + + )
{
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Move Z positive" ) ;
testRunner . ClickByName ( "Next Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
testRunner . ClickByName ( "Next Button" ) ;
2017-01-19 12:35:33 -08:00
}
2017-01-10 17:20:24 -08:00
testRunner . ClickByName ( "Done Button" ) ;
2017-02-01 10:12:31 -08:00
testRunner . Delay ( 1 ) ;
2017-01-12 14:18:04 -08:00
2017-01-10 17:20:24 -08:00
// print a part
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-05-19 14:39:57 -07:00
2017-06-02 21:07:54 -07:00
testRunner . Delay ( ( ) = > emulator . ZPosition > 5 , 3 ) ;
2017-01-10 17:20:24 -08:00
2017-06-02 21:07:54 -07:00
// assert the leveling is working
2017-01-10 17:30:27 -08:00
Assert . Greater ( emulator . ZPosition , 5 ) ;
2017-01-10 17:20:24 -08:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Cancel Print Button" ) ;
2017-01-10 17:20:24 -08:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:07:54 -07:00
} , maxTimeToRun : 90 ) ;
2017-01-10 17:20:24 -08:00
}
2017-02-01 10:20:50 -08:00
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-05-19 14:39:57 -07:00
public void ExpectedEmulatorResponses ( )
{
string [ ] test1 = new string [ ]
{
"N1 M110 N1 * 125" ,
"ok" ,
"N2 M114 * 37" ,
"X:0.00 Y: 0.00 Z: 0.00 E: 0.00 Count X: 0.00 Y: 0.00 Z: 0.00" ,
"ok" ,
"N3 M105 * 36" ,
"ok T:27.0 / 0.0" ,
"N1 M110 N1*125" ,
"ok" ,
"N2 M115 * 36" ,
"FIRMWARE_NAME:Marlin V1; Sprinter/grbl mashup for gen6 FIRMWARE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:Framelis v1 EXTRUDER_COUNT:1 UUID:155f84b5-d4d7-46f4-9432-667e6876f37a" ,
"ok" ,
"N3 M104 T0 S0 * 34" ,
"ok" ,
"N4 M104 T1 S0 * 36" ,
"ok" ,
"N5 M105 * 34" ,
"ok T:27.0 / 0.0" ,
"N6 M105 * 45" ,
"Error:checksum mismatch, Last Line: 5" ,
"Resend: 6" ,
"ok" ,
"N6 M105 * 33" ,
"ok T:27.0 / 0.0" ,
"N7 M105 * 32" ,
"ok T:27.0 / 0.0" ,
"N8 M105 * 47" ,
"ok T:27.0 / 0.0" ,
"N9 M105 * 46" ,
"ok T:27.0 / 0.0" ,
"N10 M105 * 22" ,
"ok T:27.0 / 0.0" ,
"N11 M105 * 23" ,
"ok T:27.0 / 0.0" ,
"N12 M105 * 20" ,
"ok T:27.0 / 0.0" ,
"N13 M105 * 21" ,
"ok T:27.0 / 0.0" ,
"N14 M105 * 18" ,
"ok T:27.0 / 0.0" ,
"N15 M105 * 19" ,
"ok T:27.0 / 0.0" ,
"N16 M105 * 16" ,
"ok T:27.0 / 0.0" ,
"N17 M105 * 40" ,
"Error:checksum mismatch, Last Line: 16" ,
"Resend: 17" ,
"ok" ,
"N17 M105 * 17" ,
"ok T:27.0 / 0.0" ,
} ;
string [ ] test2 = new string [ ]
{
"N1 M110 N1*125" ,
"ok" ,
"N1 M110 N1*125" ,
"ok" ,
"N1 M110 N1*125" ,
"ok" ,
"N2 M114*37" ,
"X:0.00 Y: 0.00 Z: 0.00 E: 0.00 Count X: 0.00 Y: 0.00 Z: 0.00" ,
"ok" ,
} ;
SimulatePrint ( test1 ) ;
SimulatePrint ( test2 ) ;
}
private static void SimulatePrint ( string [ ] sendRecieveLog )
{
2017-06-11 08:12:56 -07:00
using ( var emulator = new Emulator ( ) )
2017-05-19 14:39:57 -07:00
{
2017-09-22 23:50:32 -07:00
emulator . HasHeatedBed = false ;
2017-06-11 08:12:56 -07:00
int lineIndex = 0 ;
while ( lineIndex < sendRecieveLog . Length )
2017-05-19 14:39:57 -07:00
{
2017-06-11 08:12:56 -07:00
var sentCommand = sendRecieveLog [ lineIndex ] ;
string response = emulator . GetCorrectResponse ( sentCommand ) ;
lineIndex + + ;
var lines = response . Split ( '\n' ) ;
for ( int i = 0 ; i < lines . Length ; i + + )
2017-05-19 14:39:57 -07:00
{
2017-06-11 08:12:56 -07:00
if ( ! string . IsNullOrEmpty ( lines [ i ] ) )
{
Assert . AreEqual ( sendRecieveLog [ lineIndex ] , lines [ i ] ) ;
lineIndex + + ;
}
2017-05-19 14:39:57 -07:00
}
}
}
}
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-05-19 14:39:57 -07:00
public async Task PrinterRequestsResumeWorkingAsExpected ( )
{
2017-06-02 21:20:56 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-05-19 14:39:57 -07:00
{
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
2017-05-19 14:39:57 -07:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-06-02 19:39:29 -07:00
testRunner . SwitchToAdvancedSliceSettings ( ) ;
2017-05-19 14:39:57 -07:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "General Tab" ) ;
testRunner . ClickByName ( "Single Print Tab" ) ;
2017-09-14 14:47:08 -07:00
testRunner . ClickByName ( "Layer(s) To Pause Field" ) ;
2017-05-19 14:39:57 -07:00
testRunner . Type ( "2;6" ) ;
2017-06-13 13:22:22 -07:00
testRunner . ClickByName ( "Pin Settings Button" ) ;
2017-05-19 14:39:57 -07:00
// print a part
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-05-19 14:39:57 -07:00
// turn on line error simulation
emulator . SimulateLineErrors = true ;
// close the pause dialog pop-up (resume)
2017-06-14 14:02:29 -07:00
testRunner . WaitForName ( "No Button" , 90 ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "No Button" ) ;
2017-05-19 14:39:57 -07:00
// simulate board reboot
2017-06-02 21:20:56 -07:00
emulator . SimulateReboot ( ) ;
2017-05-19 14:39:57 -07:00
// close the pause dialog pop-up (resume)
2017-06-14 14:02:29 -07:00
testRunner . Delay ( 3 ) ;
testRunner . WaitForName ( "No Button" , 90 ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "No Button" ) ;
2017-05-19 14:39:57 -07:00
// Wait for done
2017-06-02 21:20:56 -07:00
testRunner . WaitForPrintFinished ( ) ;
2017-05-19 14:39:57 -07:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:20:56 -07:00
} , maxTimeToRun : 90 ) ;
2017-05-19 14:39:57 -07:00
}
2017-02-01 10:20:50 -08:00
private EventHandler unregisterEvents ;
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-03-09 12:44:20 -08:00
public async Task TuningAdjustmentsDefaultToOneAndPersists ( )
2017-02-01 10:20:50 -08:00
{
2017-02-02 13:38:49 -08:00
double targetExtrusionRate = 1.5 ;
double targetFeedRate = 2 ;
2017-06-02 21:42:19 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-02-01 10:20:50 -08:00
{
2017-06-14 14:02:29 -07:00
testRunner . WaitForName ( "Cancel Wizard Button" ) ;
2017-02-01 10:20:50 -08:00
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
2017-02-01 10:20:50 -08:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-09-16 21:22:23 -07:00
2017-06-13 13:22:22 -07:00
testRunner . SwitchToControlsTab ( ) ;
2017-06-02 21:48:49 -07:00
2017-06-02 21:42:19 -07:00
// Wait for printing to complete
var printFinishedResetEvent = new AutoResetEvent ( false ) ;
2017-09-17 21:08:16 -07:00
ApplicationController . Instance . ActivePrinter . Connection . PrintFinished . RegisterEvent ( ( s , e ) = > printFinishedResetEvent . Set ( ) , ref unregisterEvents ) ;
2017-02-01 10:20:50 -08:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-02-01 10:20:50 -08:00
2017-06-14 14:02:29 -07:00
var container = testRunner . GetWidgetByName ( "ManualPrinterControls.ControlsContainer" , out _ , 5 ) ;
2017-02-01 10:20:50 -08:00
// Scroll the widget into view
2017-02-24 08:39:31 -08:00
var scrollable = container . Parents < ManualPrinterControls > ( ) . First ( ) . Children < ScrollableWidget > ( ) . First ( ) ;
2017-02-01 10:20:50 -08:00
var width = scrollable . Width ;
// Workaround needed to scroll to the bottom of the Controls panel
//scrollable.ScrollPosition = new Vector2();
scrollable . ScrollPosition = new Vector2 ( 0 , 30 ) ;
// Workaround to force layout to fix problems with size of Tuning Widgets after setting ScrollPosition manually
scrollable . Width = width - 1 ;
scrollable . Width = width ;
2017-02-02 13:38:49 -08:00
// Tuning values should default to 1 when missing
ConfirmExpectedSpeeds ( testRunner , 1 , 1 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
testRunner . Delay ( ) ;
2017-02-01 10:20:50 -08:00
testRunner . ClickByName ( "Extrusion Multiplier NumberEdit" ) ;
testRunner . Type ( targetExtrusionRate . ToString ( ) ) ;
testRunner . ClickByName ( "Feed Rate NumberEdit" ) ;
testRunner . Type ( targetFeedRate . ToString ( ) ) ;
2017-02-02 13:38:49 -08:00
// Force focus away from the feed rate field, causing an persisted update
2017-06-13 13:22:22 -07:00
testRunner . ClickByName ( "Extrusion Multiplier NumberEdit" ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Wait for slicing to complete before setting target values
2017-09-17 21:08:16 -07:00
testRunner . Delay ( ( ) = > ApplicationController . Instance . ActivePrinter . Connection . DetailedPrintingState = = DetailedPrintingState . Printing , 8 ) ;
2017-02-02 13:38:49 -08:00
testRunner . Delay ( ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
2017-02-01 10:20:50 -08:00
2017-06-02 21:42:19 -07:00
printFinishedResetEvent . WaitOne ( ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
2017-06-02 21:42:19 -07:00
testRunner . WaitForPrintFinished ( ) ;
2017-02-01 10:20:50 -08:00
// Restart the print
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-02-01 13:07:29 -08:00
testRunner . Delay ( 2 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
testRunner . CancelPrint ( ) ;
testRunner . Delay ( 1 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
2017-02-01 10:20:50 -08:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:42:19 -07:00
} , overrideHeight : 900 , maxTimeToRun : 120 ) ;
2017-02-02 13:38:49 -08:00
}
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-03-09 12:44:20 -08:00
public async Task TuningAdjustmentControlsBoundToStreamValues ( )
{
double targetExtrusionRate = 1.5 ;
double targetFeedRate = 2 ;
double initialExtrusionRate = 0.6 ;
double initialFeedRate = 0.7 ;
2017-06-02 21:48:49 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-03-09 12:44:20 -08:00
{
2017-06-14 14:02:29 -07:00
testRunner . WaitForName ( "Cancel Wizard Button" ) ;
2017-03-09 12:44:20 -08:00
// Set custom adjustment values
FeedRateMultiplyerStream . FeedRateRatio = initialFeedRate ;
ExtrusionMultiplyerStream . ExtrusionRatio = initialExtrusionRate ;
// Then validate that they are picked up
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
2017-03-09 12:44:20 -08:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-06-02 21:48:49 -07:00
2017-06-13 13:22:22 -07:00
testRunner . SwitchToControlsTab ( ) ;
2017-03-09 12:44:20 -08:00
2017-06-02 21:48:49 -07:00
var printFinishedResetEvent = new AutoResetEvent ( false ) ;
2017-09-17 21:08:16 -07:00
ApplicationController . Instance . ActivePrinter . Connection . PrintFinished . RegisterEvent ( ( s , e ) = > printFinishedResetEvent . Set ( ) , ref unregisterEvents ) ;
2017-06-02 21:48:49 -07:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-03-09 12:44:20 -08:00
2017-06-12 20:35:48 -07:00
var container = testRunner . GetWidgetByName ( "ManualPrinterControls.ControlsContainer" , out _ , 5 ) ;
2017-03-09 12:44:20 -08:00
// Scroll the widget into view
var scrollable = container . Parents < ManualPrinterControls > ( ) . First ( ) . Children < ScrollableWidget > ( ) . First ( ) ;
var width = scrollable . Width ;
// Workaround needed to scroll to the bottom of the Controls panel
//scrollable.ScrollPosition = new Vector2();
scrollable . ScrollPosition = new Vector2 ( 0 , 30 ) ;
// Workaround to force layout to fix problems with size of Tuning Widgets after setting ScrollPosition manually
scrollable . Width = width - 1 ;
scrollable . Width = width ;
// Tuning values should match
ConfirmExpectedSpeeds ( testRunner , initialExtrusionRate , initialFeedRate ) ;
testRunner . Delay ( ) ;
testRunner . ClickByName ( "Extrusion Multiplier NumberEdit" ) ;
testRunner . Type ( targetExtrusionRate . ToString ( ) ) ;
testRunner . ClickByName ( "Feed Rate NumberEdit" ) ;
testRunner . Type ( targetFeedRate . ToString ( ) ) ;
// Force focus away from the feed rate field, causing an persisted update
2017-06-13 13:22:22 -07:00
testRunner . SwitchToControlsTab ( ) ;
2017-03-09 12:44:20 -08:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
// Wait for slicing to complete before setting target values
2017-09-17 21:08:16 -07:00
testRunner . Delay ( ( ) = > ApplicationController . Instance . ActivePrinter . Connection . DetailedPrintingState = = DetailedPrintingState . Printing , 8 ) ;
2017-03-09 12:44:20 -08:00
testRunner . Delay ( ) ;
// Values should remain after print completes
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
// Wait for printing to complete
2017-06-02 21:48:49 -07:00
printFinishedResetEvent . WaitOne ( ) ;
2017-03-09 12:44:20 -08:00
2017-06-02 21:48:49 -07:00
testRunner . WaitForPrintFinished ( ) ;
2017-03-09 12:44:20 -08:00
// Values should match entered values
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-03-09 12:44:20 -08:00
testRunner . Delay ( 2 ) ;
// Values should match entered values
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
testRunner . CancelPrint ( ) ;
testRunner . Delay ( 1 ) ;
// Values should match entered values
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate ) ;
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:48:49 -07:00
} , overrideHeight : 900 , maxTimeToRun : 120 ) ;
2017-03-09 12:44:20 -08:00
}
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-06-21 07:43:40 -07:00
public async Task CloseShouldNotStopSDPrint ( )
2017-03-07 17:52:44 -08:00
{
2017-06-02 21:54:23 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-03-07 17:52:44 -08:00
{
2017-06-14 14:02:29 -07:00
testRunner . WaitForName ( "Cancel Wizard Button" ) ;
2017-03-07 17:52:44 -08:00
2017-09-23 09:19:32 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( runSlow : true ) )
2017-03-07 17:52:44 -08:00
{
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-06-21 07:43:40 -07:00
testRunner . WaitForName ( "SD Card Row Item Collection" ) ;
testRunner . NavigateToFolder ( "SD Card Row Item Collection" ) ;
testRunner . ClickByName ( "Row Item Item 1.gcode" ) ;
testRunner . ClickByName ( "Print Library Overflow Menu" , delayBeforeReturn : 1 ) ;
testRunner . ClickByName ( "Print Menu Item" ) ;
2017-03-07 17:52:44 -08:00
testRunner . Delay ( 2 ) ;
int tempChangedCount = 0 ;
int fanChangedCount = 0 ;
emulator . ExtruderTemperatureChanged + = ( s , e ) = >
{
tempChangedCount + + ;
} ;
emulator . FanSpeedChanged + = ( s , e ) = >
{
fanChangedCount + + ;
} ;
2017-08-30 13:41:49 -07:00
testRunner . CloseMatterControlViaUi ( ) ;
2017-03-07 17:52:44 -08:00
testRunner . ClickByName ( "Yes Button" ) ;
testRunner . Delay ( 2 ) ;
Assert . AreEqual ( 0 , tempChangedCount , "We should not change this while exiting an sd card print." ) ;
Assert . AreEqual ( 0 , fanChangedCount , "We should not change this while exiting an sd card print." ) ;
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:54:23 -07:00
} , overrideHeight : 900 , maxTimeToRun : 90 ) ;
2017-03-07 17:52:44 -08:00
}
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-03-07 17:52:44 -08:00
public async Task CancelingNormalPrintTurnsHeatAndFanOff ( )
{
2017-06-02 21:54:23 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-03-07 17:52:44 -08:00
{
2017-06-14 14:02:29 -07:00
testRunner . WaitForName ( "Cancel Wizard Button" ) ;
2017-03-07 17:52:44 -08:00
2017-06-02 19:57:15 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
2017-03-07 17:52:44 -08:00
{
2017-09-16 20:53:38 -07:00
var resetEvent = new AutoResetEvent ( false ) ;
2017-03-07 17:52:44 -08:00
Assert . IsTrue ( ProfileManager . Instance . ActiveProfile ! = null ) ;
2017-06-03 19:08:14 -07:00
testRunner . AddDefaultFileToBedplate ( ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Start Print Button" ) ;
2017-03-07 17:52:44 -08:00
int fanChangedCount = 0 ;
emulator . FanSpeedChanged + = ( s , e ) = >
{
fanChangedCount + + ;
} ;
2017-09-17 14:01:58 -07:00
var layerTwoZHeight = ApplicationController . Instance . ActivePrinter . Settings . GetValue < double > ( SettingsKey . layer_height ) * 2 ;
2017-09-16 20:53:38 -07:00
// Wait for layer 2
emulator . ZPositionChanged + = ( s , e ) = >
{
// Wait for print to start, then slow down the emulator and continue. Failing to slow down frequently causes a timing issue where the print
// finishes before we make it down to 'CloseMatterControlViaUi' and thus no prompt to close appears and the test fails when clicking 'Yes Button'
if ( emulator . ZPosition > = layerTwoZHeight )
{
emulator . RunSlow = true ;
resetEvent . Set ( ) ;
}
} ;
resetEvent . WaitOne ( ) ;
// Close MatterControl and cancel print
testRunner . CloseMatterControlViaUi ( ) ;
2017-03-07 17:52:44 -08:00
testRunner . ClickByName ( "Yes Button" ) ;
2017-09-16 20:53:38 -07:00
// Wait for Disconnected CommunicationState which occurs after PrinterConnection.Disable()
testRunner . WaitForCommunicationStateDisconnected ( maxSeconds : 30 ) ;
// Wait for M106 change
testRunner . Delay ( ( ) = > fanChangedCount > 0 , 15 , 500 ) ;
// Assert expected temp targets and fan transitions
Assert . AreEqual ( 0 , ( int ) emulator . Hotend . TargetTemperature , "Unexpected target temperature - MC close should call Connection.Disable->TurnOffBedAndExtruders to shutdown heaters" ) ;
Assert . AreEqual ( 0 , ( int ) emulator . HeatedBed . TargetTemperature , "Unexpected target temperature - MC close should call Connection.Disable->TurnOffBedAndExtruders to shutdown heaters" ) ;
Assert . AreEqual ( 1 , fanChangedCount , "Unexpected fan speed change count - MC close should call Connection.Disable which shuts down fans via M106" ) ;
2017-03-07 17:52:44 -08:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-06-02 21:54:23 -07:00
} , overrideHeight : 900 , maxTimeToRun : 90 ) ;
2017-03-07 17:52:44 -08:00
}
2017-02-02 13:38:49 -08:00
private static void ConfirmExpectedSpeeds ( AutomationRunner testRunner , double targetExtrusionRate , double targetFeedRate )
{
SystemWindow systemWindow ;
SolidSlider slider ;
// Assert the UI has the expected values
slider = testRunner . GetWidgetByName ( "Extrusion Multiplier Slider" , out systemWindow , 5 ) as SolidSlider ;
2017-09-16 21:22:23 -07:00
Assert . IsTrue ( targetExtrusionRate = = slider . Value ) ;
2017-02-02 13:38:49 -08:00
slider = testRunner . GetWidgetByName ( "Feed Rate Slider" , out systemWindow , 5 ) as SolidSlider ;
2017-09-16 21:22:23 -07:00
Assert . IsTrue ( targetFeedRate = = slider . Value ) ;
2017-02-02 13:38:49 -08:00
testRunner . Delay ( . 2 ) ;
// Assert the changes took effect on the model
2017-09-16 21:22:23 -07:00
Assert . IsTrue ( targetExtrusionRate = = ExtrusionMultiplyerStream . ExtrusionRatio ) ;
Assert . IsTrue ( targetFeedRate = = FeedRateMultiplyerStream . FeedRateRatio ) ;
2017-02-01 10:20:50 -08:00
}
2017-01-03 10:45:16 -08:00
}
}