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 ;
2019-04-29 14:58:28 -07:00
using MatterHackers.MatterControl.PrintHistory ;
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
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should be defined after add" ) ;
2017-01-03 10:45:16 -08:00
2019-01-06 13:28:37 -08:00
testRunner . SelectSliceSettingsField ( PrinterSettings . Layout . Printer , "end_gcode" ) ;
2018-01-07 14:53:42 -08:00
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
2019-01-06 13:28:37 -08:00
testRunner . SelectSliceSettingsField ( PrinterSettings . Layout . Printer , "start_gcode" ) ;
2018-07-30 17:02:36 -07:00
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2018-11-12 14:45:53 -08:00
2018-07-30 17:02:36 -07:00
// Validate GCode fields persist values
Assert . AreEqual (
"G28" ,
2018-11-12 14:45:53 -08:00
printer . Settings . GetValue ( SettingsKey . end_gcode ) ,
2018-07-30 17:02:36 -07:00
"Failure persisting GCode/MultilineTextField value" ) ;
2017-10-27 14:19:26 -07:00
testRunner . AddItemToBedplate ( ) ;
2017-01-03 10:45:16 -08:00
2018-07-12 22:49:39 -07:00
// Shorten the delay so the test runs in a reasonable time
2018-11-12 14:45:53 -08:00
printer . Connection . TimeToHoldTemperature = 5 ;
2018-02-02 09:27:06 -08:00
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer ) ;
2017-01-03 10:45:16 -08:00
2017-06-02 17:04:02 -07:00
// Wait for print to finish
2018-11-30 12:53:43 -08:00
testRunner . WaitForPrintFinished ( printer ) ;
2017-06-02 17:04:02 -07:00
// Wait for expected temp
2018-11-12 14:45:53 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . GetActualHotendTemperature ( 0 ) < = 0 , 10 ) ;
Assert . Less ( printer . Connection . GetActualHotendTemperature ( 0 ) , 30 ) ;
2017-06-02 17:04:02 -07:00
// Wait for expected temp
2018-11-12 14:45:53 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . ActualBedTemperature < = 10 ) ;
Assert . Less ( printer . Connection . ActualBedTemperature , 10 ) ;
2018-01-02 16:45:02 -08:00
2018-01-08 12:04:14 -08:00
// Make sure we can run this whole thing again
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer ) ;
2018-01-08 12:04:14 -08:00
// Wait for print to finish
2018-11-30 12:53:43 -08:00
testRunner . WaitForPrintFinished ( printer ) ;
2018-01-08 12:04:14 -08:00
// Wait for expected temp
2018-11-12 14:45:53 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . GetActualHotendTemperature ( 0 ) < = 0 , 10 ) ;
Assert . Less ( printer . Connection . GetActualHotendTemperature ( 0 ) , 30 ) ;
2018-01-08 12:04:14 -08:00
// Wait for expected temp
2018-11-12 14:45:53 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . ActualBedTemperature < = 10 ) ;
Assert . Less ( printer . 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 ;
2018-02-02 09:17:04 -08:00
} , maxTimeToRun : 95 ) ;
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")]
2019-04-30 10:56:49 -07:00
public async Task PulseLevelingTest ( )
2017-01-10 17:20:24 -08:00
{
2019-04-30 10:56:49 -07:00
// Validates the Pulse profile requires leveling and it works as expected
2017-06-02 21:07:54 -07:00
await MatterControlUtilities . RunTest ( ( testRunner ) = >
2017-01-10 17:20:24 -08:00
{
2018-10-22 17:28:22 -07:00
AutomationRunner . TimeToMoveMouse = . 2 ;
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
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should be defined after add" ) ;
2017-01-10 17:20:24 -08:00
2020-07-18 08:37:40 -07:00
testRunner . OpenPrintPopupMenu ( )
. ClickByName ( "SetupPrinter" )
. Complete9StepLeveling ( )
. AddItemToBedplate ( ) ;
2018-10-18 08:19:20 -07:00
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2018-11-12 14:45:53 -08:00
var currentSettings = printer . Settings ;
2018-10-18 08:19:20 -07:00
currentSettings . SetValue ( SettingsKey . pause_gcode , "" ) ;
currentSettings . SetValue ( SettingsKey . resume_gcode , "" ) ;
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer , pauseAtLayers : "2" ) ;
2017-12-14 21:59:41 -08:00
2018-11-29 14:13:08 -08:00
testRunner . WaitForName ( "Yes Button" , 20 ) ; // the yes button is 'Resume'
2018-10-18 08:19:20 -07:00
2018-11-12 14:45:53 -08:00
// the user types in the pause layer 1 based and we are 0 based, so we should be on: user 2, printer 1.
2018-10-18 08:19:20 -07:00
Assert . AreEqual ( 1 , printer . Connection . CurrentlyPrintingLayer ) ;
2017-01-10 17:20:24 -08:00
2017-06-02 21:07:54 -07:00
// assert the leveling is working
2019-05-02 09:11:17 -07:00
Assert . AreEqual ( 11.25 , emulator . Destination . Z ) ;
2017-01-10 17:20:24 -08:00
2017-12-14 21:59:41 -08:00
testRunner . CancelPrint ( ) ;
2018-10-18 08:19:20 -07:00
// now run leveling again and make sure we get the same result
testRunner . SwitchToControlsTab ( ) ;
2019-05-29 17:01:44 -07:00
testRunner . ClickByName ( "Printer Calibration Button" ) ;
2019-04-15 21:04:28 -07:00
testRunner . ClickByName ( "Print Leveling Row" ) ;
2018-10-18 08:19:20 -07:00
testRunner . Complete9StepLeveling ( 2 ) ;
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer , pauseAtLayers : "2" ) ;
2018-10-18 08:19:20 -07:00
2018-11-29 14:13:08 -08:00
testRunner . WaitForName ( "Yes Button" , 20 ) ; // the yes button is 'Resume'
2018-10-18 08:19:20 -07:00
2018-11-12 14:45:53 -08:00
// the user types in the pause layer 1 based and we are 0 based, so we should be on: user 2, printer 1.
2018-10-18 08:19:20 -07:00
Assert . AreEqual ( 1 , printer . Connection . CurrentlyPrintingLayer ) ;
// assert the leveling is working
2019-05-02 09:11:17 -07:00
Assert . AreEqual ( 12.25 , emulator . Destination . Z ) ;
2018-10-22 17:28:22 -07:00
testRunner . CancelPrint ( ) ;
2018-11-29 13:41:24 -08:00
// now modify the leveling data manually and assert that it is applied when printing
2018-10-22 17:28:22 -07:00
testRunner . SwitchToControlsTab ( ) ;
2019-05-29 17:01:44 -07:00
testRunner . ClickByName ( "Printer Calibration Button" ) ;
2018-10-22 17:28:22 -07:00
testRunner . ClickByName ( "Edit Leveling Data Button" ) ;
2019-04-30 10:56:49 -07:00
for ( int i = 0 ; i < 3 ; i + + )
2018-10-22 17:28:22 -07:00
{
var name = $"z Position {i}" ;
testRunner . ClickByName ( name ) ;
testRunner . Type ( "^a" ) ; // select all
testRunner . Type ( "5" ) ;
}
testRunner . ClickByName ( "Save Leveling Button" ) ;
2019-05-29 17:01:44 -07:00
testRunner . ClickByName ( "Cancel Wizard Button" ) ;
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer , pauseAtLayers : "2" ) ;
2018-10-22 17:28:22 -07:00
2018-11-29 14:13:08 -08:00
testRunner . WaitForName ( "Yes Button" , 20 ) ; // the yes button is 'Resume'
2018-10-22 17:28:22 -07:00
2018-11-12 14:45:53 -08:00
// the user types in the pause layer 1 based and we are 0 based, so we should be on: user 2, printer 1.
2018-10-22 17:28:22 -07:00
Assert . AreEqual ( 1 , printer . Connection . CurrentlyPrintingLayer ) ;
2018-11-12 14:45:53 -08:00
2018-10-22 17:28:22 -07:00
// assert the leveling is working
2019-05-02 09:11:17 -07:00
Assert . AreEqual ( 5.25 , emulator . Destination . Z ) ;
2017-01-10 17:20:24 -08:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2018-10-22 17:28:22 -07:00
} , maxTimeToRun : 130 ) ;
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 ( )
{
2018-01-15 20:58:14 -08:00
// TODO: Emulator behavior should emulate actual printer firmware and use configuration rather than M104/M109 sends to set extruder count
2018-01-15 20:10:22 -08:00
//
// Quirky emulator returns single extruder M105 responses until after the first M104, at which point it extends its extruder count to match
string M105ResponseBeforeM104 = "ok T:27.0 / 0.0" ;
string M105ResponseAfterM104 = "ok T0:27.0 / 0.0 T1:27.0 / 0.0" ;
2017-05-19 14:39:57 -07:00
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" ,
2018-01-15 20:10:22 -08:00
M105ResponseBeforeM104 ,
2017-05-19 14:39:57 -07:00
"N1 M110 N1*125" ,
"ok" ,
"N2 M115 * 36" ,
2020-07-02 15:45:22 -07:00
"MatterControl Printer Emulator" ,
"Commands:" ,
" SLOW // make the emulator simulate actual printing speeds (default)" ,
" FAST // run as fast as possible" ,
"Emulating:" ,
2017-05-19 14:39:57 -07:00
"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" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N6 M105 * 45" ,
"Error:checksum mismatch, Last Line: 5" ,
"Resend: 6" ,
"ok" ,
"N6 M105 * 33" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N7 M105 * 32" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N8 M105 * 47" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N9 M105 * 46" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N10 M105 * 22" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N11 M105 * 23" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N12 M105 * 20" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N13 M105 * 21" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N14 M105 * 18" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N15 M105 * 19" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N16 M105 * 16" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
"N17 M105 * 40" ,
"Error:checksum mismatch, Last Line: 16" ,
"Resend: 17" ,
"ok" ,
"N17 M105 * 17" ,
2018-01-15 20:10:22 -08:00
M105ResponseAfterM104 ,
2017-05-19 14:39:57 -07:00
} ;
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" ,
2019-04-30 10:56:49 -07:00
"ok" ,
2017-05-19 14:39:57 -07:00
} ;
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
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should be defined after add" ) ;
2017-05-19 14:39:57 -07:00
// print a part
2017-10-27 14:19:26 -07:00
testRunner . AddItemToBedplate ( ) ;
2017-12-14 16:26:59 -08:00
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( testRunner . FirstPrinter ( ) , pauseAtLayers : "2;6" ) ;
2017-05-19 14:39:57 -07:00
// turn on line error simulation
emulator . SimulateLineErrors = true ;
// close the pause dialog pop-up (resume)
2018-11-29 14:13:08 -08:00
testRunner . WaitForName ( "Yes Button" , 20 ) ; // the yes button is 'Resume'
2018-09-21 09:48:48 -07:00
testRunner . ClickByName ( "Yes 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 ) ;
2018-09-21 09:48:48 -07:00
testRunner . WaitForName ( "Yes Button" , 20 ) ;
testRunner . ClickByName ( "Yes Button" ) ;
2017-05-19 14:39:57 -07:00
// Wait for done
2018-11-30 13:04:25 -08:00
testRunner . WaitForPrintFinished ( testRunner . FirstPrinter ( ) ) ;
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
}
2020-07-16 07:59:57 -07:00
[Test, Category("Emulator")]
public async Task PrinterDeletedWhilePrinting ( )
{
await MatterControlUtilities . RunTest ( ( testRunner ) = >
{
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
{
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should exist after add" ) ;
var printer = testRunner . FirstPrinter ( ) ;
// print a part
testRunner . AddItemToBedplate ( ) ;
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer , pauseAtLayers : "2" ) ;
2020-07-16 07:59:57 -07:00
ProfileManager . DebugPrinterDelete = true ;
// Wait for pause dialog
testRunner . ClickResumeButton ( printer , true , 1 ) ;
// Wait for done
testRunner . WaitForPrintFinished ( printer ) ;
}
return Task . CompletedTask ;
} , maxTimeToRun : 180 ) ;
}
2017-11-01 13:57:45 -07:00
[Test, Category("Emulator")]
public async Task PrinterRecoveryTest ( )
{
await MatterControlUtilities . RunTest ( ( testRunner ) = >
{
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( ) )
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should exist after add" ) ;
2018-11-12 14:45:53 -08:00
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2018-10-05 09:24:57 -07:00
printer . Settings . SetValue ( SettingsKey . recover_is_enabled , "1" ) ;
printer . Settings . SetValue ( SettingsKey . has_hardware_leveling , "0" ) ;
2017-11-01 13:57:45 -07:00
2018-10-05 09:24:57 -07:00
Assert . IsTrue ( printer . Connection . RecoveryIsEnabled ) ;
2018-07-12 11:51:47 -07:00
2017-11-01 13:57:45 -07:00
// print a part
2020-07-18 08:37:40 -07:00
testRunner . AddItemToBedplate ( )
2020-08-09 08:23:22 -07:00
. StartPrint ( printer , pauseAtLayers : "2;4;6" )
2020-07-18 08:37:40 -07:00
. ClickResumeButton ( printer , true , 1 ) // Resume
. ClickResumeButton ( printer , false , 3 ) // close the pause dialog pop-up do not resume
. ClickByName ( "Disconnect from printer button" )
. ClickByName ( "Connect to printer button" ) // Reconnect
. WaitFor ( ( ) = > printer . Connection . CommunicationState = = CommunicationStates . Connected ) ;
2018-01-07 16:11:44 -08:00
2017-11-01 13:57:45 -07:00
// Assert that recovery happens
2019-04-29 14:58:28 -07:00
Assert . IsTrue ( PrintRecovery . RecoveryAvailable ( printer ) , "Recovery should be enabled after Disconnect while printing" ) ;
2017-12-14 17:23:30 -08:00
2017-11-01 13:57:45 -07:00
// Recover the print
2020-07-18 08:37:40 -07:00
testRunner . ClickButton ( "Yes Button" , "Recover Print" )
. ClickResumeButton ( printer , true , 5 ) // The first pause that we get after recovery should be layer 6.
. WaitForPrintFinished ( printer ) ;
2017-11-01 13:57:45 -07:00
}
return Task . CompletedTask ;
} , maxTimeToRun : 180 ) ;
}
2020-08-08 22:39:08 -07:00
[Test, Category("Emulator")]
2020-08-09 08:23:22 -07:00
public async Task RecoveryT1NoProbe ( )
{
await ExtruderT1RecoveryTest ( "Airwolf 3D" , "HD" ) ;
}
[Test, Category("Emulator")]
public async Task RecoveryT1WithProbe ( )
{
await ExtruderT1RecoveryTest ( "Pulse" , "S-500" ) ;
}
public async Task ExtruderT1RecoveryTest ( string make , string model )
2020-08-08 22:39:08 -07:00
{
await MatterControlUtilities . RunTest ( ( testRunner ) = >
{
2020-08-09 08:23:22 -07:00
using ( var emulator = testRunner . LaunchAndConnectToPrinterEmulator ( make , model ) )
2020-08-08 22:39:08 -07:00
{
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should exist after add" ) ;
var printer = testRunner . FirstPrinter ( ) ;
2020-08-09 08:23:22 -07:00
testRunner . ChangeSettings (
new ( string , string ) [ ]
{
( SettingsKey . recover_is_enabled , "1" ) ,
( SettingsKey . extruder_count , "2" ) ,
( SettingsKey . has_hardware_leveling , "0" ) ,
} , printer ) ;
2020-08-08 22:39:08 -07:00
Assert . IsTrue ( printer . Connection . RecoveryIsEnabled ) ;
// print a part
testRunner . AddItemToBedplate ( )
. ClickByName ( "ItemMaterialButton" )
2020-08-09 08:23:22 -07:00
. ClickByName ( "Material 2 Button" )
. StartPrint ( printer , pauseAtLayers : "2;3;4;5" ) ;
2020-08-08 22:39:08 -07:00
testRunner . ClickResumeButton ( printer , true , 1 ) ; // Resume
// make sure we are printing with extruder 2 (T1)
Assert . AreEqual ( 0 , printer . Connection . GetTargetHotendTemperature ( 0 ) ) ;
Assert . Greater ( printer . Connection . GetTargetHotendTemperature ( 1 ) , 0 ) ;
2020-08-09 08:23:22 -07:00
testRunner . ClickResumeButton ( printer , false , 2 ) // close the pause dialog pop-up do not resume
2020-08-08 22:39:08 -07:00
. ClickByName ( "Disconnect from printer button" )
. ClickByName ( "Connect to printer button" ) // Reconnect
. WaitFor ( ( ) = > printer . Connection . CommunicationState = = CommunicationStates . Connected ) ;
// Assert that recovery happens
Assert . IsTrue ( PrintRecovery . RecoveryAvailable ( printer ) , "Recovery should be enabled after Disconnect while printing" ) ;
// Recover the print
testRunner . ClickButton ( "Yes Button" , "Recover Print" ) ;
2020-08-09 08:23:22 -07:00
// The first pause that we get after recovery should be layer 4 (index 3).
testRunner . ClickResumeButton ( printer , true , 3 ) ;
2020-08-08 22:39:08 -07:00
// make sure we are printing with extruder 2 (T1)
Assert . AreEqual ( 0 , printer . Connection . GetTargetHotendTemperature ( 0 ) ) ;
Assert . Greater ( printer . Connection . GetTargetHotendTemperature ( 1 ) , 0 ) ;
2020-08-09 08:23:22 -07:00
testRunner . ClickResumeButton ( printer , true , 4 ) ;
2020-08-08 22:39:08 -07:00
testRunner . WaitForPrintFinished ( printer ) ;
}
return Task . CompletedTask ;
} , maxTimeToRun : 180 ) ;
}
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
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should be defined after add" ) ;
2017-02-01 10:20:50 -08:00
2017-10-27 14:19:26 -07:00
testRunner . AddItemToBedplate ( ) ;
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
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2018-11-12 14:45:53 -08:00
2017-06-02 21:42:19 -07:00
// Wait for printing to complete
var printFinishedResetEvent = new AutoResetEvent ( false ) ;
2018-11-12 14:45:53 -08:00
printer . Connection . PrintFinished + = ( s , e ) = >
2018-02-01 20:57:54 -08:00
{
printFinishedResetEvent . Set ( ) ;
2018-11-09 11:47:19 -08:00
} ;
2017-02-01 10:20:50 -08:00
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer )
2020-07-18 08:37:40 -07:00
. ScrollIntoView ( "Extrusion Multiplier NumberEdit" )
. ScrollIntoView ( "Feed Rate NumberEdit" ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Tuning values should default to 1 when missing
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , 1 , 1 , "Initial case" ) ;
2017-02-01 10:20:50 -08:00
2020-07-18 08:37:40 -07:00
testRunner . Delay ( )
. ClickByName ( "Extrusion Multiplier NumberEdit" )
. Type ( targetExtrusionRate . ToString ( ) )
. ClickByName ( "Feed Rate NumberEdit" )
. Type ( targetFeedRate . ToString ( ) )
// Force focus away from the feed rate field, causing an persisted update
. ClickByName ( "Extrusion Multiplier NumberEdit" ) ;
2017-02-01 10:20:50 -08:00
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After setting TextEdit values" ) ;
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
2018-11-12 14:45:53 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . DetailedPrintingState = = DetailedPrintingState . Printing , 8 ) ;
2017-02-02 13:38:49 -08:00
testRunner . Delay ( ) ;
2017-02-01 10:20:50 -08:00
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "While printing" ) ;
2017-02-01 10:20:50 -08:00
2018-02-01 20:57:54 -08:00
// Wait up to 60 seconds for the print to finish
printFinishedResetEvent . WaitOne ( 60 * 1000 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After print finished" ) ;
2017-02-02 13:38:49 -08:00
2020-07-18 08:37:40 -07:00
testRunner . WaitForPrintFinished ( printer )
2020-08-09 08:23:22 -07:00
. StartPrint ( printer ) // Restart the print
2020-07-18 08:37:40 -07:00
. Delay ( 1 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After print restarted" ) ;
2017-02-01 10:20:50 -08:00
2020-07-18 08:37:40 -07:00
testRunner . CancelPrint ( )
. Delay ( 1 ) ;
2017-02-01 10:20:50 -08:00
2017-02-02 13:38:49 -08:00
// Values should match entered values
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After canceled print" ) ;
2017-02-01 10:20:50 -08:00
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2019-04-30 10:56:49 -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
// 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
{
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should be defined after add" ) ;
2017-03-09 12:44:20 -08:00
2017-10-27 14:19:26 -07:00
testRunner . AddItemToBedplate ( ) ;
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
2018-11-30 13:04:25 -08:00
var printer = testRunner . FirstPrinter ( ) ;
2017-12-14 21:59:41 -08:00
2020-07-01 21:59:06 -07:00
// Set custom adjustment values
2020-07-02 15:45:22 -07:00
printer . Settings . SetValue ( SettingsKey . feedrate_ratio , initialFeedRate . ToString ( ) ) ;
printer . Settings . SetValue ( SettingsKey . extrusion_ratio , initialExtrusionRate . ToString ( ) ) ;
2020-07-01 21:59:06 -07:00
2017-06-02 21:48:49 -07:00
var printFinishedResetEvent = new AutoResetEvent ( false ) ;
2018-11-09 11:47:19 -08:00
printer . Connection . PrintFinished + = ( s , e ) = > printFinishedResetEvent . Set ( ) ;
2017-06-02 21:48:49 -07:00
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer ) ;
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
2018-01-15 20:50:03 -08:00
var scrollable = container . Parents < ManualPrinterControls > ( ) . FirstOrDefault ( ) as ScrollableWidget ;
2017-03-09 12:44:20 -08:00
var width = scrollable . Width ;
// Workaround needed to scroll to the bottom of the Controls panel
2019-04-30 10:56:49 -07:00
// scrollable.ScrollPosition = new Vector2();
2017-03-09 12:44:20 -08:00
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 ;
2018-04-19 07:58:03 -07:00
// Tuning values should match
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , initialExtrusionRate , initialFeedRate , "Initial case" ) ;
2017-03-09 12:44:20 -08:00
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
2018-07-31 17:36:22 -07:00
testRunner . ClickByName ( "Extrusion Multiplier NumberEdit" ) ;
2017-03-09 12:44:20 -08:00
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After setting TextEdit values" ) ;
2017-03-09 12:44:20 -08:00
// Wait for slicing to complete before setting target values
2017-12-15 19:28:25 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . DetailedPrintingState = = DetailedPrintingState . Printing , 8 ) ;
2017-03-09 12:44:20 -08:00
testRunner . Delay ( ) ;
// Values should remain after print completes
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "While printing" ) ;
2017-03-09 12:44:20 -08:00
// Wait for printing to complete
2017-06-02 21:48:49 -07:00
printFinishedResetEvent . WaitOne ( ) ;
2017-03-09 12:44:20 -08:00
2018-11-30 12:53:43 -08:00
testRunner . WaitForPrintFinished ( printer ) ;
2017-03-09 12:44:20 -08:00
// Values should match entered values
2020-08-09 08:23:22 -07:00
testRunner . StartPrint ( printer ) ;
2017-12-15 19:28:25 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . CommunicationState = = CommunicationStates . Printing , 15 ) ;
2017-03-09 12:44:20 -08:00
// Values should match entered values
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "While reprinting" ) ;
2017-03-09 12:44:20 -08:00
testRunner . CancelPrint ( ) ;
2017-12-15 19:28:25 -08:00
testRunner . WaitFor ( ( ) = > printer . Connection . CommunicationState = = CommunicationStates . Connected , 15 ) ;
2017-03-09 12:44:20 -08:00
// Values should match entered values
2018-07-31 17:36:22 -07:00
ConfirmExpectedSpeeds ( testRunner , targetExtrusionRate , targetFeedRate , "After cancel" ) ;
2017-03-09 12:44:20 -08:00
}
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
{
2017-06-21 07:43:40 -07:00
testRunner . NavigateToFolder ( "SD Card Row Item Collection" ) ;
testRunner . ClickByName ( "Row Item Item 1.gcode" ) ;
2017-12-06 17:21:53 -08:00
testRunner . ClickByName ( "Print Library Overflow Menu" ) ;
2017-06-21 07:43:40 -07:00
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-12-14 21:59:41 -08:00
testRunner . CloseMatterControl ( ) ;
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 ;
2018-06-26 11:06:32 -07:00
} , maxTimeToRun : 90 ) ;
2017-03-07 17:52:44 -08:00
}
2017-06-11 07:59:13 -07:00
[Test, Category("Emulator")]
2017-11-30 14:50:54 -08:00
public async Task CancelingPrintTurnsHeatAndFanOff ( )
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-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 ) ;
2018-11-12 17:20:59 -08:00
Assert . AreEqual ( 1 , ApplicationController . Instance . ActivePrinters . Count ( ) , "One printer should exist after add" ) ;
2017-03-07 17:52:44 -08:00
2017-10-27 14:19:26 -07:00
testRunner . AddItemToBedplate ( ) ;
2017-03-07 17:52:44 -08:00
2020-08-09 08:23:22 -07:00
var printer = testRunner . FirstPrinter ( ) ;
testRunner . StartPrint ( printer ) ;
2018-04-19 07:58:03 -07:00
2017-03-07 17:52:44 -08:00
int fanChangedCount = 0 ;
emulator . FanSpeedChanged + = ( s , e ) = >
{
fanChangedCount + + ;
} ;
2017-12-14 21:59:41 -08:00
emulator . WaitForLayer ( printer . Settings , 2 ) ;
emulator . RunSlow = true ;
2018-04-19 07:58:03 -07:00
2017-11-30 14:48:32 -08:00
// Click close but cancel
2017-12-14 21:59:41 -08:00
testRunner . CloseMatterControl ( ) ;
2017-11-30 14:48:32 -08:00
testRunner . ClickByName ( "No Button" ) ;
// Wait for close
2017-12-15 20:29:16 -08:00
testRunner . WaitForWidgetDisappear ( "Yes Button" , 4 ) ;
2017-11-30 14:48:32 -08:00
testRunner . Delay ( 2 ) ;
// Confirm abort
2017-12-16 19:09:25 -08:00
Assert . IsFalse ( AppContext . RootSystemWindow . HasBeenClosed , "Canceling Close dialog should *not* close MatterControl" ) ;
2017-11-30 14:48:32 -08:00
2017-09-16 20:53:38 -07:00
// Close MatterControl and cancel print
2017-12-14 21:59:41 -08:00
testRunner . CloseMatterControl ( ) ;
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()
2018-11-30 12:53:43 -08:00
testRunner . WaitForCommunicationStateDisconnected ( printer , maxSeconds : 30 ) ;
2017-09-16 20:53:38 -07:00
2017-11-30 14:48:32 -08:00
// Wait for close
2017-12-15 20:29:16 -08:00
testRunner . WaitForWidgetDisappear ( "Yes Button" , 4 ) ;
2017-11-30 14:48:32 -08:00
testRunner . Delay ( 2 ) ;
// Confirm close
2017-12-16 19:09:25 -08:00
Assert . IsTrue ( AppContext . RootSystemWindow . HasBeenClosed , "Confirming Close dialog *should* close MatterControl" ) ;
2017-11-30 14:48:32 -08:00
2017-09-16 20:53:38 -07:00
// Wait for M106 change
2017-12-15 19:28:25 -08:00
testRunner . WaitFor ( ( ) = > fanChangedCount > 0 , 15 , 500 ) ;
2017-09-16 20:53:38 -07:00
// Assert expected temp targets and fan transitions
2018-01-10 12:55:41 -08:00
Assert . AreEqual ( 0 , ( int ) emulator . CurrentExtruder . TargetTemperature , "Unexpected target temperature - MC close should call Connection.Disable->TurnOffBedAndExtruders to shutdown heaters" ) ;
2017-09-16 20:53:38 -07:00
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
}
2018-07-31 17:36:22 -07:00
private static void ConfirmExpectedSpeeds ( AutomationRunner testRunner , double targetExtrusionRate , double targetFeedRate , string scope )
2017-02-02 13:38:49 -08:00
{
SolidSlider slider ;
// Assert the UI has the expected values
2020-07-01 21:59:06 -07:00
slider = testRunner . GetWidgetByName ( "Extrusion Multiplier Slider" , out _ ) as SolidSlider ;
2018-07-31 17:36:22 -07:00
testRunner . WaitFor ( ( ) = > targetExtrusionRate = = slider . Value ) ;
2017-02-02 13:38:49 -08:00
2018-07-31 17:36:22 -07:00
Assert . AreEqual ( targetExtrusionRate , slider . Value , $"Unexpected Extrusion Rate Slider Value - {scope}" ) ;
2017-02-02 13:38:49 -08:00
2020-07-01 21:59:06 -07:00
slider = testRunner . GetWidgetByName ( "Feed Rate Slider" , out _ ) as SolidSlider ;
2018-07-31 17:36:22 -07:00
testRunner . WaitFor ( ( ) = > targetFeedRate = = slider . Value ) ;
Assert . AreEqual ( targetFeedRate , slider . Value , $"Unexpected Feed Rate Slider Value - {scope}" ) ;
2017-02-02 13:38:49 -08:00
2020-07-01 21:59:06 -07:00
var printer = testRunner . FirstPrinter ( ) ;
2017-02-02 13:38:49 -08:00
// Assert the changes took effect on the model
2020-07-01 21:59:06 -07:00
testRunner . WaitFor ( ( ) = > targetExtrusionRate = = printer . Connection . ExtrusionMultiplierStream . ExtrusionRatio ) ;
Assert . AreEqual ( targetExtrusionRate , printer . Connection . ExtrusionMultiplierStream . ExtrusionRatio , $"Unexpected Extrusion Rate - {scope}" ) ;
2018-07-31 17:36:22 -07:00
2020-07-01 21:59:06 -07:00
testRunner . WaitFor ( ( ) = > targetFeedRate = = printer . Connection . FeedRateMultiplierStream . FeedRateRatio ) ;
Assert . AreEqual ( targetFeedRate , printer . Connection . FeedRateMultiplierStream . FeedRateRatio , $"Unexpected Feed Rate - {scope}" ) ;
2017-02-01 10:20:50 -08:00
}
2017-01-03 10:45:16 -08:00
}
}