Skip to content

Commit

Permalink
[dotnet] Use selenium manager in tests (#11871)
Browse files Browse the repository at this point in the history
* Copy manager binaries to tests output

* Use selenium manager implicitly to execute tests

* Trigger tests again

* Revert "Trigger tests again"

This reverts commit 6dde845.

* 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 <diemol@users.noreply.github.com>
  • Loading branch information
nvborisenko and diemol authored Apr 19, 2023
1 parent bd7bdcb commit 5055da9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
8 changes: 5 additions & 3 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
// limitations under the License.
// </copyright>

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;
Expand All @@ -37,6 +38,7 @@ namespace OpenQA.Selenium
/// </summary>
public static class SeleniumManager
{
private static string basePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private static string binary;

/// <summary>
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions dotnet/src/webdriver/build/Selenium.WebDriver.targets
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Selenium_Manager_BinariesRootPath Condition="$(Selenium_Manager_BinariesRootPath) == ''">$(MSBuildThisFileDirectory)..\manager</Selenium_Manager_BinariesRootPath>
</PropertyGroup>

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\manager\linux\selenium-manager">
<None Include="$(Selenium_Manager_BinariesRootPath)\linux\selenium-manager">
<Link>selenium-manager\linux\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>

<None Include="$(MSBuildThisFileDirectory)..\manager\macos\selenium-manager">
<None Include="$(Selenium_Manager_BinariesRootPath)\macos\selenium-manager">
<Link>selenium-manager\macos\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>

<None Include="$(MSBuildThisFileDirectory)..\manager\windows\selenium-manager.exe">
<None Include="$(Selenium_Manager_BinariesRootPath)\windows\selenium-manager.exe">
<Link>selenium-manager\windows\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
Expand Down
3 changes: 3 additions & 0 deletions dotnet/test/common/FormHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions dotnet/test/common/WebDriver.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@
<Exec Command="$(ProjectDir)WebDriver.Common.Tests.csproj.prebuild.sh $(ProjectDir)" />
</Target>

<!-- It is automatically imported when Selenium.WebDriver consumed via nuget package -->
<PropertyGroup>
<Selenium_Manager_BinariesRootPath>..\..\..\common\manager</Selenium_Manager_BinariesRootPath>
</PropertyGroup>
<Import Project="..\..\src\webdriver\build\Selenium.WebDriver.targets" />

</Project>

0 comments on commit 5055da9

Please sign in to comment.