diff options
author | Manish Sinha <manish.sinha@xamarin.com> | 2015-09-28 23:49:06 +0300 |
---|---|---|
committer | Manish Sinha <manish.sinha@xamarin.com> | 2015-09-29 18:14:22 +0300 |
commit | e1090df1261cbeda789ac170b3653abe8097c000 (patch) | |
tree | 91007ad501496b818787750b991068765a4f3589 /main/tests | |
parent | 46ba26d34a388a1eabcb4151a3f52215b650ecf4 (diff) |
[UITest] Add ReproStep to NuGet tests
Diffstat (limited to 'main/tests')
4 files changed, 81 insertions, 43 deletions
diff --git a/main/tests/UserInterfaceTests/Controllers/NuGetController.cs b/main/tests/UserInterfaceTests/Controllers/NuGetController.cs index 06c3c65965..a27ac6f97d 100644 --- a/main/tests/UserInterfaceTests/Controllers/NuGetController.cs +++ b/main/tests/UserInterfaceTests/Controllers/NuGetController.cs @@ -46,28 +46,37 @@ namespace UserInterfaceTests readonly Func<AppQuery,AppQuery> resultList; readonly Func<AppQuery,AppQuery> includePreRelease; - public static void AddPackage (NuGetPackageOptions packageOptions, Action<string> takeScreenshot = null) + public static void AddPackage (NuGetPackageOptions packageOptions, UITestBase testContext = null) { - AddUpdatePackage (packageOptions, takeScreenshot, false); + Action<string> screenshotAction = delegate { }; + if (testContext != null) { + testContext.ReproStep (string.Format ("Add NuGet package '{0}'", packageOptions.PackageName), packageOptions); + screenshotAction = testContext.TakeScreenShot; + } + AddUpdatePackage (packageOptions, screenshotAction, false); } - public static void UpdatePackage (NuGetPackageOptions packageOptions, Action<string> takeScreenshot = null) + public static void UpdatePackage (NuGetPackageOptions packageOptions, UITestBase testContext = null) { - AddUpdatePackage (packageOptions, takeScreenshot, true); + Action<string> screenshotAction = delegate { }; + if (testContext != null) { + testContext.ReproStep (string.Format ("Update NuGet package '{0}'", packageOptions.PackageName), packageOptions); + screenshotAction = testContext.TakeScreenShot; + } + AddUpdatePackage (packageOptions, screenshotAction, true); } - public static void UpdateAllNuGetPackages (Action<string> takeScreenshot = null) + public static void UpdateAllNuGetPackages (UITestBase testContext = null) { Session.ExecuteCommand ("MonoDevelop.PackageManagement.Commands.UpdateAllPackagesInSolution"); WaitForNuGet.UpdateSuccess (string.Empty); - if (takeScreenshot != null) - takeScreenshot ("All-NuGet-Packages-Updated"); + if (testContext != null) + testContext.TakeScreenShot ("All-NuGet-Packages-Updated"); } static void AddUpdatePackage (NuGetPackageOptions packageOptions, Action<string> takeScreenshot, bool isUpdate = false) { packageOptions.PrintData (); - takeScreenshot = takeScreenshot ?? delegate {}; var nuget = new NuGetController (takeScreenshot, isUpdate); nuget.Open (); nuget.EnterSearchText (packageOptions.PackageName, packageOptions.Version, packageOptions.IsPreRelease); diff --git a/main/tests/UserInterfaceTests/Controllers/NuGetOptions.cs b/main/tests/UserInterfaceTests/Controllers/NuGetOptions.cs index e634c2a314..9fb53d57cb 100644 --- a/main/tests/UserInterfaceTests/Controllers/NuGetOptions.cs +++ b/main/tests/UserInterfaceTests/Controllers/NuGetOptions.cs @@ -85,24 +85,29 @@ namespace UserInterfaceTests Operation, PackageName, WaitForSuccess, WaitForWarning, WaitForError, TimeOutSeconds, PollStepSeconds); } - public static void UpdateSuccess (string packageName, bool waitForWarning = true) + public static void UpdateSuccess (string packageName, bool waitForWarning = true, UITestBase testContext = null) { - Success (packageName, NuGetOperations.Update, waitForWarning); + Success (packageName, NuGetOperations.Update, waitForWarning, testContext); } - public static void AddSuccess (string packageName, bool waitForWarning = true) + public static void AddSuccess (string packageName, bool waitForWarning = true, UITestBase testContext = null) { - Success (packageName, NuGetOperations.Add, waitForWarning); + Success (packageName, NuGetOperations.Add, waitForWarning, testContext); } - public static void Success (string packageName, NuGetOperations operation, bool waitForWarning = true) + public static void Success (string packageName, NuGetOperations operation, bool waitForWarning = true, UITestBase testContext = null) { - new WaitForNuGet { + var waitPackage = new WaitForNuGet { Operation = operation, PackageName = packageName, WaitForSuccess = true, WaitForWarning = waitForWarning - }.Wait (); + }; + if (testContext != null) { + testContext.ReproStep (string.Format ("Wait for one of these messages:\n\t{0}", + string.Join ("\t\n", waitPackage.ToMessages ()))); + } + waitPackage.Wait (); } public void Wait () diff --git a/main/tests/UserInterfaceTests/DialogTests/NuGetDialogTests.cs b/main/tests/UserInterfaceTests/DialogTests/NuGetDialogTests.cs index fdf6fb6d2c..3163eeb0b4 100644 --- a/main/tests/UserInterfaceTests/DialogTests/NuGetDialogTests.cs +++ b/main/tests/UserInterfaceTests/DialogTests/NuGetDialogTests.cs @@ -49,7 +49,7 @@ namespace UserInterfaceTests PackageName = "CommandLineParser", Version = "2.0.257-beta", IsPreRelease = true - }, TakeScreenShot); + }, this); } [Test, Timeout(300000)] @@ -68,20 +68,27 @@ namespace UserInterfaceTests PackageName = "CommandLineParser", Version = "1.9.3.34", IsPreRelease = false - }, TakeScreenShot); + }, this); string solutionFolder = GetSolutionDirectory (); string solutionPath = Path.Combine (solutionFolder, projectDetails.SolutionName+".sln"); var projectPath = Path.Combine (solutionFolder, projectDetails.ProjectName, projectDetails.ProjectName + ".csproj"); Assert.IsTrue (File.Exists (projectPath)); - TakeScreenShot ("About-To-Close-Solution"); - Session.ExecuteCommand (FileCommands.CloseWorkspace); - TakeScreenShot ("Closed-Solution"); + Workbench.CloseWorkspace (this); - Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workspace.OpenWorkspaceItem", new FilePath (solutionPath), true); - TakeScreenShot ("Solution-Opened"); - Assert.Throws <TimeoutException> (() => Ide.WaitForPackageUpdate ()); + Workbench.OpenWorkspace (solutionPath, this); + try { + const string expected = "When a solution is opened and package updates are available, it don't show in status bar"; + ReproStep (expected); + Ide.WaitForPackageUpdate (); + var failureMessage = string.Format ("Expected: {0}\nActual: {1}", + expected, "When a solution is opened and package updates are available, it shows in status bar"); + ReproStep (failureMessage); + Assert.Fail (failureMessage); + } catch (TimeoutException) { + Session.DebugObject.Debug ("WaitForPackageUpdate throws TimeoutException as expected"); + } Ide.WaitForSolutionLoaded (); TakeScreenShot ("Solution-Ready"); } @@ -95,7 +102,7 @@ namespace UserInterfaceTests PackageName = "RestSharp", Version = "105.2.3", IsPreRelease = true - }, TakeScreenShot); + }, this); WaitForNuGetReadmeOpened (); } @@ -108,8 +115,9 @@ namespace UserInterfaceTests PackageName = "RestSharp", Version = "105.2.2", IsPreRelease = true - }, TakeScreenShot); + }, this); WaitForNuGetReadmeOpened (); + Session.ExecuteCommand (FileCommands.CloseFile); Session.WaitForElement (IdeQuery.TextArea); TakeScreenShot ("About-To-Update-Package"); @@ -117,7 +125,7 @@ namespace UserInterfaceTests PackageName = "RestSharp", Version = "105.2.3", IsPreRelease = true - }, TakeScreenShot); + }, this); WaitForNuGetReadmeOpened (); } @@ -132,7 +140,7 @@ namespace UserInterfaceTests }; var projectDetails = CreateProject (); - NuGetController.AddPackage (packageInfo, TakeScreenShot); + NuGetController.AddPackage (packageInfo, this); WaitForNuGetReadmeOpened (); Session.ExecuteCommand (FileCommands.CloseFile); @@ -147,8 +155,16 @@ namespace UserInterfaceTests CreateProject (pclTemplateOptions, pclProjectDetails); SolutionExplorerController.SelectProject (projectDetails.SolutionName, pclProjectDetails.ProjectName); - NuGetController.AddPackage (packageInfo, TakeScreenShot); - Assert.Throws<TimeoutException> (WaitForNuGetReadmeOpened); + NuGetController.AddPackage (packageInfo, this); + try { + WaitForNuGetReadmeOpened (false); + var failureMessage = string.Format ("Expected: {0}\nActual:{1}", + "readme.txt tab should not open", "readme.txt tab opens"); + ReproStep (failureMessage); + Assert.Fail (failureMessage); + } catch (TimeoutException) { + Session.DebugObject.Debug ("readme.txt tab failed to open as expected"); + } } [Test] @@ -159,12 +175,12 @@ namespace UserInterfaceTests CreateProject (); NuGetController.AddPackage (new NuGetPackageOptions { PackageName = "Newtonsoft.Json", - }, TakeScreenShot); - WaitForNuGet.Success ("Newtonsoft.Json", NuGetOperations.Add, false); + }, this); + WaitForNuGet.Success ("Newtonsoft.Json", NuGetOperations.Add, false, this); TakeScreenShot ("NewtonSoftJson-Package-Added-Without-Warning"); } - [Test] + [Test, Timeout (300000)] [Description ("When a NuGet package is updated, the 'Local Copy' value should be preserved")] public void TestLocalCopyPreservedUpdate () { @@ -180,26 +196,24 @@ namespace UserInterfaceTests PackageName = "CommandLineParser", Version = "1.9.71", IsPreRelease = false - }, TakeScreenShot); + }, this); string solutionFolder = GetSolutionDirectory (); string solutionPath = Path.Combine (solutionFolder, projectDetails.SolutionName+".sln"); var projectPath = Path.Combine (solutionFolder, projectDetails.ProjectName, projectDetails.ProjectName + ".csproj"); Assert.IsTrue (File.Exists (projectPath)); - TakeScreenShot ("About-To-Close-Solution"); - Session.ExecuteCommand (FileCommands.CloseWorkspace); - TakeScreenShot ("Closed-Solution"); + ReproStep ("Check 'Local Copy' on CommandLine package under References"); + + Workbench.CloseWorkspace (this); AddOrCheckLocalCopy (projectPath, true); - Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workspace.OpenWorkspaceItem", new FilePath (solutionPath), true); - TakeScreenShot ("Solution-Opened"); - Ide.WaitForPackageUpdateExtra (new List<string> { "Solution loaded." }); - TakeScreenShot ("Solution-Ready"); + Workbench.OpenWorkspace (solutionPath, this); - NuGetController.UpdateAllNuGetPackages (TakeScreenShot); + NuGetController.UpdateAllNuGetPackages (this); + ReproStep ("Check if CommandLine package under References has 'Local Copy' checked"); AddOrCheckLocalCopy (projectPath, false); } @@ -250,9 +264,18 @@ namespace UserInterfaceTests return projectDetails; } - void WaitForNuGetReadmeOpened () + void WaitForNuGetReadmeOpened (bool expectSuccess = true) { - Session.WaitForElement (c => c.Window ().Marked ("MonoDevelop.Ide.Gui.DefaultWorkbench").Property ("TabControl.CurrentTab.Text", "readme.txt")); + ReproStep ("Wait for tab with readme.txt to be opened"); + try { + Session.WaitForElement (c => c.Window ().Marked ("MonoDevelop.Ide.Gui.DefaultWorkbench").Property ("TabControl.CurrentTab.Text", "readme.txt")); + } catch (TimeoutException) { + if (expectSuccess) { + ReproStep (string.Format ("Expected: {0}\nActual: {1}", + "readme.txt tab should open", "readm.txt tab did not open")); + } + throw; + } } } } diff --git a/main/tests/UserInterfaceTests/Workbench.cs b/main/tests/UserInterfaceTests/Workbench.cs index 8f9ea9047f..89f2a65b5b 100644 --- a/main/tests/UserInterfaceTests/Workbench.cs +++ b/main/tests/UserInterfaceTests/Workbench.cs @@ -99,6 +99,7 @@ namespace UserInterfaceTests testContext.ReproStep (string.Format ("Open solution path '{0}'", solutionPath)); Action<string> takeScreenshot = GetScreenshotAction (testContext); Session.GlobalInvoke ("MonoDevelop.Ide.IdeApp.Workspace.OpenWorkspaceItem", new FilePath (solutionPath), true); + Ide.WaitForSolutionLoaded (); takeScreenshot ("Solution-Opened"); } |