Ensure spawned emulator process is always killed via using/Dispose

- LaunchAndConnectToPrinterEmulator -> TestRunner extension method
This commit is contained in:
John Lewin 2016-10-26 07:27:16 -07:00
parent 3c1066b0aa
commit b54b73db7f
4 changed files with 72 additions and 83 deletions

View file

@ -49,15 +49,13 @@ namespace MatterHackers.MatterControl.Tests.Automation
[Test, Apartment(ApartmentState.STA)]
public async Task SoftwareLevelingRequiredCorrectWorkflow()
{
Process emulatorProcess = null;
AutomationTest testToRun = (testRunner) =>
{
MatterControlUtilities.PrepForTestRun(testRunner);
// make a jump start printer
emulatorProcess = MatterControlUtilities.LaunchAndConnectToPrinterEmulator(testRunner, false, "JumStart", "V1");
using (var emulatorProcess = testRunner.LaunchAndConnectToPrinterEmulator("JumpStart", "V1", runSlow: false))
{
// make sure it is showing the correct button
Assert.IsTrue(!testRunner.WaitForName("Start Print Button", .5), "Start Print hidden");
Assert.IsTrue(testRunner.WaitForName("Finish Setup Button", .5), "Finish Setup showing");
@ -74,11 +72,11 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.ClickByName("Next Button", .5);
}
Assert.IsTrue(testRunner.ClickByName("Done Button", .5), "Found Done button");
Assert.IsTrue(testRunner.ClickByName("Done Button", 1), "Found Done button");
// make sure the button has changed to start print
Assert.IsTrue(testRunner.WaitForName("Start Print Button", .5), "Start Print showing");
Assert.IsTrue(!testRunner.WaitForName("Finish Setup Button", .5), "Finish Setup hidden");
Assert.IsTrue(testRunner.WaitForName("Start Print Button", 5), "Start Print showing");
Assert.IsTrue(!testRunner.WaitForName("Finish Setup Button", 1), "Finish Setup hidden");
// reset to defaults and make sure print leveling is cleared
MatterControlUtilities.SwitchToAdvancedSettings(testRunner);
@ -89,19 +87,14 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.Wait(1);
// make sure it is showing the correct button
Assert.IsTrue(!testRunner.WaitForName("Start Print Button", .5), "Start Print hidden");
Assert.IsTrue(testRunner.WaitForName("Finish Setup Button", .5), "Finish Setup showing");
Assert.IsTrue(!testRunner.WaitForName("Start Print Button", 1), "Start Print hidden");
Assert.IsTrue(testRunner.WaitForName("Finish Setup Button", 1), "Finish Setup showing");
return Task.FromResult(0);
}
};
await MatterControlUtilities.RunTest(testToRun);
try
{
emulatorProcess?.Kill();
}
catch { }
}
}
}

View file

@ -21,11 +21,13 @@ namespace MatterHackers.MatterControl.Tests.Automation
MatterControlUtilities.PrepForTestRun(testRunner);
SystemWindow systemWindow;
string copyButtonName = "3D View Copy";
//Navigate to Local Library
testRunner.ClickByName("Library Tab");
testRunner.NavigateToFolder("Local Library Row Item Collection");
testRunner.Wait(1);
testRunner.ClickByName("Row Item Calibration - Box");
testRunner.ClickByName("Row Item Calibration - Box View Button");
testRunner.Wait(1);
@ -34,33 +36,25 @@ namespace MatterHackers.MatterControl.Tests.Automation
GuiWidget partPreview = testRunner.GetWidgetByName("View3DWidget", out systemWindow, 3);
View3DWidget view3D = partPreview as View3DWidget;
string copyButtonName = "3D View Copy";
//Click Edit button to make edit controls visible
testRunner.ClickByName("3D View Edit");
testRunner.Wait(1);
int partCountBeforeCopy = view3D.MeshGroups.Count();
Assert.IsTrue(partCountBeforeCopy == 1);
Assert.AreEqual(view3D.MeshGroups.Count(), 1, "Should have 1 part before copy");
//Click Copy button and count MeshGroups
testRunner.ClickByName(copyButtonName);
System.Threading.Thread.Sleep(500);
int partCountAfterCopy = view3D.MeshGroups.Count();
Assert.IsTrue(partCountAfterCopy == 2);
testRunner.Wait(1);
testRunner.Wait(.5);
Assert.AreEqual(view3D.MeshGroups.Count(), 2, "Should have 2 parts after copy");
//Click Copy button a second time and count MeshGroups again
testRunner.ClickByName(copyButtonName);
System.Threading.Thread.Sleep(500);
int partCountAfterSecondCopy = view3D.MeshGroups.Count();
Assert.IsTrue(partCountAfterSecondCopy == 3);
view3D.CloseOnIdle();
testRunner.Wait(.5);
Assert.AreEqual(view3D.MeshGroups.Count(), 3, "Should have 3 parts after 2nd copy");
return Task.FromResult(0);
};
await MatterControlUtilities.RunTest(testToRun);
await MatterControlUtilities.RunTest(testToRun, overrideWidth: 800);
}
[Test, Apartment(ApartmentState.STA)]

View file

@ -27,7 +27,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
//Navigate to Local Library
testRunner.ClickByName("Library Tab");
MatterControlUtilities.NavigateToFolder(testRunner, "Local Library Row Item Collection");
testRunner.NavigateToFolder("Local Library Row Item Collection");
testRunner.Wait(1);
testRunner.ClickByName("Row Item Calibration - Box");
testRunner.ClickByName("Row Item Calibration - Box Print Button");
@ -58,14 +58,12 @@ namespace MatterHackers.MatterControl.Tests.Automation
[Test, Apartment(ApartmentState.STA)]
public async Task PauseOnLayerDoesPauseOnPrint()
{
Process emulatorProcess = null;
AutomationTest testToRun = (testRunner) =>
{
MatterControlUtilities.PrepForTestRun(testRunner, MatterControlUtilities.PrepAction.CloseSignInAndPrinterSelect);
emulatorProcess = MatterControlUtilities.LaunchAndConnectToPrinterEmulator(testRunner);
using (var emulatorProcess = testRunner.LaunchAndConnectToPrinterEmulator())
{
Assert.IsTrue(ProfileManager.Instance.ActiveProfile != null);
MatterControlUtilities.SwitchToAdvancedSettings(testRunner);
@ -91,15 +89,10 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.IsTrue(testRunner.WaitForName("Print Again Button", 1));
return Task.FromResult(0);
}
};
await MatterControlUtilities.RunTest(testToRun, maxTimeToRun: 90);
try
{
emulatorProcess?.Kill();
}
catch { }
}
private static void WaitForLayerAndResume(AutomationRunner testRunner, int indexToWaitFor)

View file

@ -130,7 +130,16 @@ namespace MatterHackers.MatterControl.Tests.Automation
}
}
public static Process LaunchAndConnectToPrinterEmulator(AutomationRunner testRunner, bool runSlow = false, string make = "Airwolf 3D", string model = "HD")
public class PrintEmulatorProcess: Process
{
protected override void Dispose(bool disposing)
{
this.Kill();
base.Dispose(disposing);
}
}
public static Process LaunchAndConnectToPrinterEmulator(this AutomationRunner testRunner, string make = "Airwolf 3D", string model = "HD", bool runSlow = false)
{
// Load the TestEnv config
var config = TestAutomationConfig.Load();
@ -138,7 +147,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
// Create the printer
MatterControlUtilities.AddAndSelectPrinter(testRunner, make, model);
var process = new Process();
var process = new PrintEmulatorProcess();
process.StartInfo = new ProcessStartInfo()
{
FileName = "python",