From 80513d89484890f74c984fd77dd42a56ee9501b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Wed, 11 Jan 2023 19:33:45 +0100 Subject: [PATCH] Add method to navigate to URI + downloading test workaround +semver: feature (#226) * Lowercase logging preference key * Add method to navigate to URI + downloading test workaround * Try to stabilize GeoLocation test --- .../src/Aquality.Selenium/Aquality.Selenium.xml | 6 ++++++ .../src/Aquality.Selenium/Browsers/Browser.cs | 9 +++++++++ .../WebDriverSettings/DriverSettings.cs | 2 +- .../Integration/DevToolsEmulationTests.cs | 1 + .../Usecases/FileDownloadingTests.cs | 17 +++++++++++++---- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml index a72405e3..d5873eaa 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml +++ b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml @@ -149,6 +149,12 @@ String representation of URL. + + + Navigates to desired URL. + + Desired URL. + Navigates back. diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs index bbd09a25..e35c40d4 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs @@ -171,6 +171,15 @@ public void GoTo(string url) Navigate().GoToUrl(url); } + /// + /// Navigates to desired URL. + /// + /// Desired URL. + public void GoTo(Uri url) + { + Navigate().GoToUrl(url); + } + /// /// Navigates back. /// diff --git a/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs b/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs index f237f740..c70cbc7e 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs @@ -182,7 +182,7 @@ protected void SetLoggingPreferences(DriverOptions options) { foreach (var preference in LoggingPreferences) { - options.SetLoggingPreference(preference.Key, preference.Value); + options.SetLoggingPreference(preference.Key.ToLower(), preference.Value); } } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs index 20531a39..373b8047 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs @@ -134,6 +134,7 @@ private static void CheckGeolocationOverride(Action s Assert.AreEqual(LongitudeForOverride, locationForm.Longitude, "Longitude should match to override value"); clearAction(); + AqualityServices.Browser.WaitForPageToLoad(); AqualityServices.Browser.Refresh(); locationForm.DetectBrowserGeolocation(); Assert.AreEqual(defaultLatitude, locationForm.Latitude, "Latitude should match to default"); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs index ceaf7d95..712e141b 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/FileDownloadingTests.cs @@ -24,13 +24,22 @@ public void Should_BePossibleTo_DownloadTextFile() var lblFileContent = AqualityServices.Get().GetLabel(By.XPath("//pre"), "text file content"); Assert.False(FileDownloadHelper.IsFileDownloaded(filePath, lblFileContent), $"file {filePath} should not exist before downloading"); + var oldWindowHandle = browser.Tabs().CurrentTabHandle; browser.ExecuteScriptFromFile("Resources.OpenUrlInNewWindow.js", downloaderForm.Url); - var tabs = new List(AqualityServices.Browser.Driver.WindowHandles); - browser.Driver.SwitchTo().Window(tabs[1]); + browser.Tabs().SwitchToLastTab(); downloaderForm.Open(); - downloaderForm.GetDownloadLink(fileName).JsActions.ClickAndWait(); - browser.Driver.SwitchTo().Window(tabs[0]); + var downloadLink = downloaderForm.GetDownloadLink(fileName); + if (downloadLink.State.IsDisplayed) + { + downloadLink.JsActions.ClickAndWait(); + } + else + { + browser.GoTo(new Uri($"{downloaderForm.Url}/{fileName}")); + } + + browser.Tabs().SwitchToTab(oldWindowHandle); bool condition() => FileDownloadHelper.IsFileDownloaded(filePath, lblFileContent); var message = $"file {filePath} was not downloaded"; try