From 0f9b5eda21ba37e0914e8d8709e4e0bbb8c306c9 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 8 Dec 2017 18:33:44 -0800 Subject: [PATCH 1/5] Use CompleteDialog helper --- Submodules/agg-sharp | 2 +- .../LibraryDownloadsTest.cs | 13 +++++-------- .../MatterControl/MatterControlUtilities.cs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 883160d3d..be5a14436 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 883160d3d769e23ba0f99466526adc2a0342eeb0 +Subproject commit be5a14436e63982ec3eaee7d0fee215fbf0e1747 diff --git a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs index 65ba56a07..d8e6756ab 100644 --- a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs +++ b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs @@ -147,24 +147,21 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.CloseSignInAndPrinterSelect(); MatterControlUtilities.CreateDownloadsSubFolder(); - //Navigate to Downloads Library Provider + // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); testRunner.NavigateToFolder("-Temporary Row Item Collection"); testRunner.ClickByName("Library Add Button"); - testRunner.Delay(2); - - testRunner.Type(MatterControlUtilities.GetTestItemPath("Batman.stl")); - testRunner.Delay(1); + + testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Batman.stl"), 2); testRunner.Type("{Enter}"); - //Rename added item + // Rename added item testRunner.ClickByName("Library Edit Button"); testRunner.ClickByName("Row Item Batman"); testRunner.LibraryRenameSelectedItem(); + testRunner.CompleteDialog("Batman Renamed", .5); - testRunner.Delay(.5); - testRunner.Type("Batman Renamed"); testRunner.ClickByName("InputBoxPage Action Button"); Assert.IsTrue(testRunner.WaitForName("Row Item Batman Renamed", 2)); diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index e88688cd3..3969f60c5 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -432,7 +432,7 @@ namespace MatterHackers.MatterControl.Tests.Automation /// /// The TestRunner to interact with /// The text to type - public static void CompleteDialog(this AutomationRunner testRunner, string textValue, int secondsToWait = 1) + public static void CompleteDialog(this AutomationRunner testRunner, string textValue, double secondsToWait = 1) { // AutomationDialog requires no delay if (AggContext.FileDialogs is AutomationDialogProvider) From 45dc43c796003c4ab87311b30d0a919578f70350 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 8 Dec 2017 18:51:57 -0800 Subject: [PATCH 2/5] Remove fixed Dialog wait times, use CompleteDialog helper --- .../LibraryDownloadsTest.cs | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs index d8e6756ab..965f49e16 100644 --- a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs +++ b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs @@ -18,27 +18,24 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.CloseSignInAndPrinterSelect(); MatterControlUtilities.CreateDownloadsSubFolder(); - //Navigate to Downloads Library Provider + // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); testRunner.NavigateToFolder("-Temporary Row Item Collection"); - testRunner.ClickByName("Library Add Button"); - testRunner.Delay(3); - - testRunner.Delay(2); // Add both files to the FileOpen dialog - testRunner.Type( + testRunner.ClickByName("Library Add Button"); + testRunner.CompleteDialog( string.Format( "\"{0}\" \"{1}\"", MatterControlUtilities.GetTestItemPath("Fennec_Fox.stl"), - MatterControlUtilities.GetTestItemPath("Batman.stl"))); + MatterControlUtilities.GetTestItemPath("Batman.stl")), + 5); testRunner.Delay(1); testRunner.Type("{Enter}"); Assert.IsTrue(testRunner.WaitForName("Row Item Fennec Fox", 2), "Fennec Fox item exists"); Assert.IsTrue(testRunner.WaitForName("Row Item Batman", 2), "Batman item exists"); - testRunner.Delay(1); return Task.CompletedTask; }; @@ -64,16 +61,13 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.CloseSignInAndPrinterSelect(); MatterControlUtilities.CreateDownloadsSubFolder(); - //Navigate to Downloads Library Provider + // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); testRunner.NavigateToFolder("-Temporary Row Item Collection"); - testRunner.ClickByName("Library Add Button"); - testRunner.Delay(2); - //Add AMF part items to Downloads and then type paths into file dialog - testRunner.Delay(2); - testRunner.Type(MatterControlUtilities.GetTestItemPath("Rook.amf")); - testRunner.Delay(1); + // Add AMF part items to Downloads and then type paths into file dialog + testRunner.ClickByName("Library Add Button"); + testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Rook.amf"), 4); testRunner.Type("{Enter}"); Assert.IsTrue(testRunner.WaitForName("Row Item Rook", 2), "Rook item exists"); @@ -105,21 +99,15 @@ namespace MatterHackers.MatterControl.Tests.Automation // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); testRunner.NavigateToFolder("-Temporary Row Item Collection"); - testRunner.ClickByName("Library Add Button"); - testRunner.Delay(2); - // Add AMF part items to Downloads and then type paths into file dialogs - testRunner.Delay(2); - testRunner.Type(MatterControlUtilities.GetTestItemPath("Test.zip")); - testRunner.Delay(1); + testRunner.ClickByName("Library Add Button"); + testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Test.zip"), 4); testRunner.Type("{Enter}"); Assert.IsTrue(testRunner.WaitForName("Row Item Chinese Dragon", 2), "Chinese Dragon item exists"); Assert.IsTrue(testRunner.WaitForName("Row Item chichen-itza pyramid", 2), "chichen-itza item exists"); Assert.IsTrue(testRunner.WaitForName("Row Item Circle Calibration", 2), "Circle Calibration item exists"); - testRunner.Delay(1); - return Task.CompletedTask; }; @@ -195,12 +183,11 @@ namespace MatterHackers.MatterControl.Tests.Automation string newFolderName = "New Folder"; testRunner.ClickByName("Create Folder From Library Button"); - testRunner.Delay(2); + testRunner.WaitForName("InputBoxPage Action Button"); testRunner.Type(newFolderName); testRunner.ClickByName("InputBoxPage Action Button"); - testRunner.Delay(2); - Assert.IsTrue(testRunner.WaitForName(newFolderName + " Row Item Collection", 2), $"{newFolderName} exists"); + Assert.IsTrue(testRunner.WaitForName(newFolderName + " Row Item Collection"), $"{newFolderName} exists"); return Task.CompletedTask; }; From 274b7d8549cad1f67ccdfc715fe48fdbed2d70e5 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 8 Dec 2017 19:02:41 -0800 Subject: [PATCH 3/5] Eliminate false positives, remove try/catch, use setup/teardown --- .../LibraryDownloadsTest.cs | 99 +++++-------------- .../MatterControl/MatterControlUtilities.cs | 12 +-- 2 files changed, 26 insertions(+), 85 deletions(-) diff --git a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs index 965f49e16..9b064e5d8 100644 --- a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs +++ b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs @@ -10,13 +10,24 @@ namespace MatterHackers.MatterControl.Tests.Automation [TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain] public class LibraryDownloadsTests { + [SetUp] + public void Setup() + { + MatterControlUtilities.CreateDownloadsSubFolder(); + } + + [TearDown] + public void TearDown() + { + MatterControlUtilities.DeleteDownloadsSubFolder(); + } + [Test, Apartment(ApartmentState.STA)] public async Task DownloadsAddButtonAddsMultipleFiles() { - AutomationTest testToRun = (testRunner) => + await MatterControlUtilities.RunTest(testRunner => { testRunner.CloseSignInAndPrinterSelect(); - MatterControlUtilities.CreateDownloadsSubFolder(); // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); @@ -38,28 +49,15 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.IsTrue(testRunner.WaitForName("Row Item Batman", 2), "Batman item exists"); return Task.CompletedTask; - }; - - // TODO: The standard assignment without a try/catch should be used and DeleteDownloadsSubFolder should be called from a TearDown method - try - { - await MatterControlUtilities.RunTest(testToRun); - - } - catch { } - finally - { - MatterControlUtilities.DeleteDownloadsSubFolder(); - } + }); } [Test, Apartment(ApartmentState.STA)] public async Task DownloadsAddButtonAddsAMFFiles() { - AutomationTest testToRun = (testRunner) => + await MatterControlUtilities.RunTest(testRunner => { testRunner.CloseSignInAndPrinterSelect(); - MatterControlUtilities.CreateDownloadsSubFolder(); // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); @@ -74,27 +72,15 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.Delay(1); return Task.CompletedTask; - }; - - try - { - await MatterControlUtilities.RunTest(testToRun); - - } - catch { } - finally - { - MatterControlUtilities.DeleteDownloadsSubFolder(); - } + }); } [Test, Apartment(ApartmentState.STA)] public async Task DownloadsAddButtonAddsZipFiles() { - AutomationTest testToRun = (testRunner) => + await MatterControlUtilities.RunTest(testRunner => { testRunner.CloseSignInAndPrinterSelect(); - MatterControlUtilities.CreateDownloadsSubFolder(); // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); @@ -109,37 +95,21 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.IsTrue(testRunner.WaitForName("Row Item Circle Calibration", 2), "Circle Calibration item exists"); return Task.CompletedTask; - }; - - try - { - MatterControlUtilities.RunTest(testToRun); - } - catch { } - - // Give MatterControl a moment to shutdown - Thread.Sleep(2000); - try - { - // Then attempt to clean up - MatterControlUtilities.DeleteDownloadsSubFolder(); - } - catch { } + }); } [Test, Apartment(ApartmentState.STA)] public async Task RenameDownloadsPrintItem() { - AutomationTest testToRun = (testRunner) => + await MatterControlUtilities.RunTest(testRunner => { testRunner.CloseSignInAndPrinterSelect(); - MatterControlUtilities.CreateDownloadsSubFolder(); // Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); testRunner.NavigateToFolder("-Temporary Row Item Collection"); testRunner.ClickByName("Library Add Button"); - + testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Batman.stl"), 2); testRunner.Type("{Enter}"); @@ -154,27 +124,15 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.IsTrue(testRunner.WaitForName("Row Item Batman Renamed", 2)); return Task.CompletedTask; - }; - - try - { - await MatterControlUtilities.RunTest(testToRun); - - } - catch { } - finally - { - MatterControlUtilities.DeleteDownloadsSubFolder(); - } + }); } [Test, Apartment(ApartmentState.STA)] public async Task CreateFolder() { - AutomationTest testToRun = (testRunner) => + await MatterControlUtilities.RunTest(testRunner => { testRunner.CloseSignInAndPrinterSelect(); - MatterControlUtilities.CreateDownloadsSubFolder(); //Navigate to Downloads Library Provider testRunner.NavigateToFolder("Downloads Row Item Collection"); @@ -190,18 +148,7 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.IsTrue(testRunner.WaitForName(newFolderName + " Row Item Collection"), $"{newFolderName} exists"); return Task.CompletedTask; - }; - - try - { - await MatterControlUtilities.RunTest(testToRun); - - } - catch { } - finally - { - MatterControlUtilities.DeleteDownloadsSubFolder(); - } + }); } } } \ No newline at end of file diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 3969f60c5..514c967ea 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -66,6 +66,8 @@ namespace MatterHackers.MatterControl.Tests.Automation private static string runName = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"); + public static string PathToDownloadsSubFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "-Temporary"); + public static void RemoveAllFromQueue(this AutomationRunner testRunner) { testRunner.ClickByName("Queue... Menu"); @@ -77,15 +79,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { Directory.CreateDirectory(PathToDownloadsSubFolder); } - - public static string PathToDownloadsSubFolder - { - get - { - return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "-Temporary"); - } - } - + public static void DeleteDownloadsSubFolder() { Directory.Delete(PathToDownloadsSubFolder, true); From 18139b85f228214a9b11a620b6b7199306b64785 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 8 Dec 2017 19:18:28 -0800 Subject: [PATCH 4/5] Empty downloads test/temp folder if not empty --- .../MatterControl/MatterControlUtilities.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 514c967ea..e1df9120d 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -76,9 +76,19 @@ namespace MatterHackers.MatterControl.Tests.Automation } public static void CreateDownloadsSubFolder() + { + if (Directory.Exists(PathToDownloadsSubFolder)) + { + foreach (string filePath in Directory.GetFiles(PathToDownloadsSubFolder)) + { + File.Delete(filePath); + } + } + else { Directory.CreateDirectory(PathToDownloadsSubFolder); } + } public static void DeleteDownloadsSubFolder() { From 637449e288799afa01cd604de069c950236528ff Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 8 Dec 2017 19:19:22 -0800 Subject: [PATCH 5/5] Fix breaking issues with Download tests --- .../LibraryDownloadsTest.cs | 23 ++++++++----------- .../MatterControl/MatterControlUtilities.cs | 6 ++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs index 9b064e5d8..c605e404b 100644 --- a/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs +++ b/Tests/MatterControl.AutomationTests/LibraryDownloadsTest.cs @@ -42,11 +42,8 @@ namespace MatterHackers.MatterControl.Tests.Automation MatterControlUtilities.GetTestItemPath("Batman.stl")), 5); - testRunner.Delay(1); - testRunner.Type("{Enter}"); - - Assert.IsTrue(testRunner.WaitForName("Row Item Fennec Fox", 2), "Fennec Fox item exists"); - Assert.IsTrue(testRunner.WaitForName("Row Item Batman", 2), "Batman item exists"); + Assert.IsTrue(testRunner.WaitForName("Row Item Fennec_Fox.stl", 2), "Fennec Fox item exists"); + Assert.IsTrue(testRunner.WaitForName("Row Item Batman.stl", 2), "Batman item exists"); return Task.CompletedTask; }); @@ -66,10 +63,8 @@ namespace MatterHackers.MatterControl.Tests.Automation // Add AMF part items to Downloads and then type paths into file dialog testRunner.ClickByName("Library Add Button"); testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Rook.amf"), 4); - testRunner.Type("{Enter}"); - Assert.IsTrue(testRunner.WaitForName("Row Item Rook", 2), "Rook item exists"); - testRunner.Delay(1); + Assert.IsTrue(testRunner.WaitForName("Row Item Rook.amf"), "Rook item exists"); return Task.CompletedTask; }); @@ -88,7 +83,6 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Library Add Button"); testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Test.zip"), 4); - testRunner.Type("{Enter}"); Assert.IsTrue(testRunner.WaitForName("Row Item Chinese Dragon", 2), "Chinese Dragon item exists"); Assert.IsTrue(testRunner.WaitForName("Row Item chichen-itza pyramid", 2), "chichen-itza item exists"); @@ -111,17 +105,18 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Library Add Button"); testRunner.CompleteDialog(MatterControlUtilities.GetTestItemPath("Batman.stl"), 2); - testRunner.Type("{Enter}"); // Rename added item - testRunner.ClickByName("Library Edit Button"); - testRunner.ClickByName("Row Item Batman"); + testRunner.ClickByName("Row Item Batman.stl"); testRunner.LibraryRenameSelectedItem(); - testRunner.CompleteDialog("Batman Renamed", .5); + + testRunner.WaitForName("InputBoxPage Action Button"); + testRunner.Type("Batman Renamed"); testRunner.ClickByName("InputBoxPage Action Button"); - Assert.IsTrue(testRunner.WaitForName("Row Item Batman Renamed", 2)); + + Assert.IsTrue(testRunner.WaitForName("Row Item Batman Renamed.stl", 2)); return Task.CompletedTask; }); diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index e1df9120d..dc8006a3f 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -85,9 +85,9 @@ namespace MatterHackers.MatterControl.Tests.Automation } } else - { - Directory.CreateDirectory(PathToDownloadsSubFolder); - } + { + Directory.CreateDirectory(PathToDownloadsSubFolder); + } } public static void DeleteDownloadsSubFolder()