From 5055da92b764f17e67dffd00617143f128b1b311 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 19 Apr 2023 14:51:07 +0300 Subject: [PATCH] [dotnet] Use selenium manager in tests (#11871) * Copy manager binaries to tests output * Use selenium manager implicitly to execute tests * Trigger tests again * Revert "Trigger tests again" This reverts commit 6dde845cefa1a54027a4109f2ee84b24054d9d3b. * Fix flaky ShouldBeAbleToUploadTheSameFileTwice tests * Remove preinstalled drivers * Remove all known pre-installed drivers * Damn powershell * Print verbose messages while deleting drivers * Return back globalization namespace --------- Co-authored-by: Diego Molina --- .github/workflows/ci-dotnet.yml | 6 +++--- dotnet/src/webdriver/SeleniumManager.cs | 8 +++++--- dotnet/src/webdriver/build/Selenium.WebDriver.targets | 10 +++++++--- dotnet/test/common/FormHandlingTests.cs | 3 +++ dotnet/test/common/WebDriver.Common.Tests.csproj | 6 ++++++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-dotnet.yml b/.github/workflows/ci-dotnet.yml index c76d835474719..5810552c4b532 100644 --- a/.github/workflows/ci-dotnet.yml +++ b/.github/workflows/ci-dotnet.yml @@ -31,10 +31,8 @@ jobs: include: - driver: Chrome browser: chrome - location: C:\SeleniumWebDrivers\ChromeDriver - driver: Firefox browser: chrome - location: C:\SeleniumWebDrivers\GeckoDriver with: name: Browser Tests (${{ matrix.driver }}, ${{ matrix.framework }}) browser: ${{ matrix.browser }} @@ -44,6 +42,8 @@ jobs: run: | bazel build //dotnet/test/common:${{ matrix.browser }} $env:ACTIVE_DRIVER_CONFIG = '${{ matrix.driver }}' - $env:DRIVER_SERVICE_LOCATION = '${{ matrix.location }}' + rm "$env:ChromeWebDriver" -r -v + rm "$env:EdgeWebDriver" -r -v + rm "$env:GeckoWebDriver" -r -v cd dotnet dotnet test test/common/WebDriver.Common.Tests.csproj --framework ${{ matrix.framework }} diff --git a/dotnet/src/webdriver/SeleniumManager.cs b/dotnet/src/webdriver/SeleniumManager.cs index 8035b5e1bdd2e..36d5a5037ba2c 100644 --- a/dotnet/src/webdriver/SeleniumManager.cs +++ b/dotnet/src/webdriver/SeleniumManager.cs @@ -16,12 +16,13 @@ // limitations under the License. // +using Newtonsoft.Json; +using OpenQA.Selenium.Internal; using System; using System.Collections.Generic; using System.Diagnostics; -using Newtonsoft.Json; -using OpenQA.Selenium.Internal; using System.Globalization; +using System.Reflection; #if !NET45 && !NET46 && !NET47 using System.Runtime.InteropServices; @@ -37,6 +38,7 @@ namespace OpenQA.Selenium /// public static class SeleniumManager { + private static string basePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); private static string binary; /// @@ -140,7 +142,7 @@ private static string Binary private static string RunCommand(string fileName, string arguments) { Process process = new Process(); - process.StartInfo.FileName = fileName; + process.StartInfo.FileName = $"{basePath}/{fileName}"; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; diff --git a/dotnet/src/webdriver/build/Selenium.WebDriver.targets b/dotnet/src/webdriver/build/Selenium.WebDriver.targets index 3d538aa2d2d10..fab907a12fb1e 100644 --- a/dotnet/src/webdriver/build/Selenium.WebDriver.targets +++ b/dotnet/src/webdriver/build/Selenium.WebDriver.targets @@ -1,20 +1,24 @@ + + $(MSBuildThisFileDirectory)..\manager + + - + selenium-manager\linux\%(Filename)%(Extension) PreserveNewest False - + selenium-manager\macos\%(Filename)%(Extension) PreserveNewest False - + selenium-manager\windows\%(Filename)%(Extension) PreserveNewest False diff --git a/dotnet/test/common/FormHandlingTests.cs b/dotnet/test/common/FormHandlingTests.cs index 43c399da49f5e..ae4935522b389 100644 --- a/dotnet/test/common/FormHandlingTests.cs +++ b/dotnet/test/common/FormHandlingTests.cs @@ -218,6 +218,9 @@ public void ShouldBeAbleToUploadTheSameFileTwice() uploadElement.SendKeys(inputFile.FullName); uploadElement.Submit(); + + // Explicitly wait next page to be loaded, Firefox is not handling elements submitting + WaitFor(() => driver.Url.EndsWith("resultPage.html"), "We are not redirected to the resultPage after submitting web element"); } inputFile.Delete(); diff --git a/dotnet/test/common/WebDriver.Common.Tests.csproj b/dotnet/test/common/WebDriver.Common.Tests.csproj index 1189bc2f6d9e6..4f3116601345b 100644 --- a/dotnet/test/common/WebDriver.Common.Tests.csproj +++ b/dotnet/test/common/WebDriver.Common.Tests.csproj @@ -63,4 +63,10 @@ + + + ..\..\..\common\manager + + +