From 83bd04564a3b7d573d42980e2830e94cb4159c6a Mon Sep 17 00:00:00 2001 From: knysh Date: Wed, 4 Sep 2019 15:58:55 +0300 Subject: [PATCH] Fix ignored tests * #145 removed ignore tag * #145 refactored assertion messages and check tests * #145 updated asserts in ExecuteAsyncJavaScript test * #145 Update BrowserTests * #145 Update test ignore comment --- .../Integration/BrowserTests.cs | 79 ++++++++----------- .../Unit/BrowserManagerTests.cs | 2 +- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs index 4d431c15..5f27babf 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs @@ -56,25 +56,24 @@ public void Should_BePossibleTo_NavigateBackAndForward() [Test] public void Should_BePossibleTo_OpenNewBrowserAfterQuit() { - var url = new WelcomeForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.Quit(); + var welcomeForm = new WelcomeForm(); + welcomeForm.Open(); + BrowserManager.Browser.Quit(); - Assert.AreNotEqual(url, BrowserManager.Browser.CurrentUrl); + Assert.AreNotEqual(welcomeForm.Url, BrowserManager.Browser.CurrentUrl); } [Test] public void Should_BePossibleTo_RefreshPage() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); var dynamicContentForm = new DynamicContentForm(); + dynamicContentForm.Open(); var firstItem = dynamicContentForm.GetContentItem(1).GetText(); + var browser = BrowserManager.Browser; browser.Refresh(); browser.WaitForPageToLoad(); + var firstItemAfterRefresh = dynamicContentForm.GetContentItem(1).GetText(); Assert.AreNotEqual(firstItem, firstItemAfterRefresh); } @@ -90,71 +89,60 @@ public void Should_BePossibleTo_SetPageLoadTimeout() [Test] public void Should_BePossibleTo_TakeScreenshot() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.WaitForPageToLoad(); - Assert.IsTrue(browser.GetScreenshot().Length > 0); + new DynamicContentForm().Open(); + Assert.IsTrue(BrowserManager.Browser.GetScreenshot().Length > 0); } [Test] public void Should_BePossibleTo_ExecuteJavaScript() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.WaitForPageToLoad(); - var currentUrl = browser.ExecuteScript("return window.location.href"); - Assert.AreEqual(url, currentUrl); + var dynamicContentForm = new DynamicContentForm(); + dynamicContentForm.Open(); + var currentUrl = BrowserManager.Browser.ExecuteScript("return window.location.href"); + Assert.AreEqual(dynamicContentForm.Url, currentUrl); } - [Ignore("Need to be fixed")] [Test] public void Should_BePossibleTo_ExecuteAsyncJavaScript() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.WaitForPageToLoad(); - var expectedDurationInSeconds = 1; - var operationDurationInSeconds = 1; + const int expectedDurationInSeconds = 1; + const int operationDurationInSeconds = 1; + + new DynamicContentForm().Open(); var stopwatch = new Stopwatch(); stopwatch.Start(); - browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds)); + BrowserManager.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds)); stopwatch.Stop(); var durationSeconds = stopwatch.Elapsed.TotalSeconds; - Assert.True(durationSeconds < (expectedDurationInSeconds + operationDurationInSeconds) && - durationSeconds >= expectedDurationInSeconds); + Assert.Multiple(() => + { + Assert.Less(durationSeconds, (expectedDurationInSeconds + operationDurationInSeconds), "Elapsed time should be less than (js + operation) duration"); + Assert.GreaterOrEqual(durationSeconds, expectedDurationInSeconds, "Elapsed time should be greater or equal than js duration"); + }); } [Test] public void Should_BePossibleTo_ExecuteAsyncJavaScript_WithScriptTimeoutException() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.WaitForPageToLoad(); - + new DynamicContentForm().Open(); var expectedDurationInSeconds = Configuration.Instance.TimeoutConfiguration.Script.TotalSeconds + 1; - Assert.Throws(() => browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds))); + Assert.Throws(() => BrowserManager.Browser.ExecuteAsyncScript(GetAsyncTimeoutJavaScript(expectedDurationInSeconds))); } private string GetAsyncTimeoutJavaScript(double expectedDurationInSeconds) { - return "window.setTimeout(arguments[arguments.length - 1], " + expectedDurationInSeconds * 1000 + ");"; + return $"window.setTimeout(arguments[arguments.length - 1], {expectedDurationInSeconds * 1000});"; } [Test] public void Should_BePossibleTo_ExecuteJavaScriptFromFile() { - var url = new DynamicContentForm().Url; - var browser = BrowserManager.Browser; - browser.GoTo(url); - browser.WaitForPageToLoad(); - var currentUrl = browser.ExecuteScriptFromFile("Resources.GetCurrentUrl.js"); - Assert.AreEqual(url, currentUrl); + var dynamicContentForm = new DynamicContentForm(); + dynamicContentForm.Open(); + var currentUrl = BrowserManager.Browser.ExecuteScriptFromFile("Resources.GetCurrentUrl.js"); + Assert.AreEqual(dynamicContentForm.Url, currentUrl); } [Test] @@ -220,12 +208,11 @@ public void Should_BePossibleTo_GetBrowserName() Assert.AreEqual(browserName, BrowserManager.Browser.BrowserName); } - [Ignore("Need to fix on Azure")] [Test] public void Should_BePossibleTo_SetImplicitWait() { var browser = BrowserManager.Browser; - browser.GoTo(new WelcomeForm().Url); + new WelcomeForm().Open(); var waitTime = TimeSpan.FromSeconds(5); browser.SetImplicitWaitTimeout(waitTime); @@ -241,8 +228,8 @@ public void Should_BePossibleTo_SetImplicitWait() } Assert.Multiple(() => { - Assert.IsTrue(elapsedTime < waitTime + TimeSpan.FromSeconds(2)); - Assert.IsTrue(elapsedTime >= waitTime); + Assert.Less(elapsedTime, waitTime + TimeSpan.FromSeconds(2), "Elapsed time should be less than implicit timeout + 2 sec(accuracy)"); + Assert.GreaterOrEqual(elapsedTime, waitTime, "Elapsed time should be greater or equal than implicit timeout"); }); } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs index 1d728910..622d39a1 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/BrowserManagerTests.cs @@ -26,7 +26,7 @@ public void Should_BeAbleGetBrowser_WithStartArguments(string startArguments) Assert.DoesNotThrow(() => BrowserManager.Browser.WaitForPageToLoad()); } - [Ignore("Not all browsers are supported")] + [Ignore("Not all browsers are supported in Azure CICD pipeline")] [TestCase(BrowserName.IExplorer)] [TestCase(BrowserName.Firefox)] [TestCase(BrowserName.Chrome)]