Skip to content

Commit bfcd9d7

Browse files
authored
Fix chrome exact version driver download (#352)
1 parent aabb3b8 commit bfcd9d7

File tree

12 files changed

+263
-254
lines changed

12 files changed

+263
-254
lines changed

.github/workflows/dotnet.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
uses: actions/setup-dotnet@v5
1616
with:
1717
dotnet-version: |
18-
3.1.x
18+
7.0.x
1919
9.0.x
2020
- name: Restore dependencies
2121
run: dotnet restore
2222
- name: Build
2323
run: dotnet build --no-restore
2424
- name: Test
2525
run: dotnet test --no-restore --no-build
26-
26+
2727
deploy:
2828
needs: build
2929
runs-on: ubuntu-latest

WebDriverManager.Tests/ChromeConfigTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ public void DriverDownloadLatestTest()
2424
}
2525

2626
[Fact]
27-
public void DriverDownloadTest()
27+
public void DriverDownloadExactTest()
2828
{
29-
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
29+
new DriverManager().SetUpDriver(new ChromeConfig(), "115.0.5763.0");
30+
Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
31+
}
3032

33+
[Fact]
34+
public void DriverDownloadMatchingBrowserTest()
35+
{
36+
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
3137
Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
3238
}
3339
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Text.RegularExpressions;
2+
using WebDriverManager.DriverConfigs.Impl;
3+
using WebDriverManager.Helpers;
4+
using Xunit;
5+
6+
namespace WebDriverManager.Tests
7+
{
8+
public class LegacyChromeConfigTests : LegacyChromeConfig
9+
{
10+
[Fact]
11+
public void VersionTest()
12+
{
13+
var version = GetLatestVersion();
14+
var regex = new Regex(@"^\d+\.\d+.\d+.\d+$");
15+
Assert.NotEmpty(version);
16+
Assert.Matches(regex, version);
17+
Assert.Equal("114.0.5735.90", version);
18+
}
19+
20+
[Fact]
21+
public void DriverDownloadLatestTest()
22+
{
23+
new DriverManager().SetUpDriver(new LegacyChromeConfig());
24+
Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
25+
}
26+
27+
[Fact]
28+
public void DriverDownloadExactTest()
29+
{
30+
new DriverManager().SetUpDriver(new LegacyChromeConfig(), "106.0.5249.61");
31+
Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
32+
}
33+
}
34+
}

WebDriverManager.Tests/LegacyEdgeConfigTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public void VersionTest()
1414
var regex = new Regex(@"^\d+\.\d+$");
1515
Assert.NotEmpty(version);
1616
Assert.Matches(regex, version);
17+
Assert.Equal("6.17134", version);
1718
}
1819

1920
[Fact]

WebDriverManager.Tests/PhantomConfigTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public void VersionTest()
1414
var regex = new Regex(@"^\d+\.\d+\.\d+$");
1515
Assert.NotEmpty(version);
1616
Assert.Matches(regex, version);
17+
Assert.Equal("2.1.1", version);
1718
}
1819

1920
[Fact]
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<CheckEolTargetFramework>false</CheckEolTargetFramework>
5-
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<PackageReference Include="coverlet.msbuild" Version="6.0.2" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
13-
<PackageReference Include="Selenium.WebDriver" Version="4.25.0" />
14-
<PackageReference Include="xunit" Version="2.9.2" />
15-
</ItemGroup>
16-
17-
<ItemGroup>
18-
<ProjectReference Include="..\WebDriverManager\WebDriverManager.csproj" />
19-
</ItemGroup>
20-
21-
<ItemGroup>
22-
<None Remove="Assets\file.txt" />
23-
<Content Include="Assets\file.txt">
24-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25-
</Content>
26-
<None Remove="Assets\removable.zip" />
27-
<Content Include="Assets\removable.zip">
28-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29-
</Content>
30-
<None Remove="Assets\unzipable.zip" />
31-
<Content Include="Assets\unzipable.zip">
32-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33-
</Content>
34-
</ItemGroup>
35-
36-
<ItemGroup>
37-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
38-
<None Update="Assets\gzip.tar.gz">
39-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
40-
</None>
41-
</ItemGroup>
42-
43-
<PropertyGroup>
44-
<VSTestLogger>trx%3bLogFileName=Results$(TargetFramework).trx</VSTestLogger>
45-
</PropertyGroup>
46-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
5+
<TargetFrameworks>net472;net7.0</TargetFrameworks>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="coverlet.msbuild" Version="6.0.2" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
13+
<PackageReference Include="Selenium.WebDriver" Version="4.25.0" />
14+
<PackageReference Include="xunit" Version="2.9.2" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\WebDriverManager\WebDriverManager.csproj" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<None Remove="Assets\file.txt" />
23+
<Content Include="Assets\file.txt">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</Content>
26+
<None Remove="Assets\removable.zip" />
27+
<Content Include="Assets\removable.zip">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</Content>
30+
<None Remove="Assets\unzipable.zip" />
31+
<Content Include="Assets\unzipable.zip">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</Content>
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
38+
<None Update="Assets\gzip.tar.gz">
39+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
40+
</None>
41+
</ItemGroup>
42+
43+
<PropertyGroup>
44+
<VSTestLogger>trx%3bLogFileName=Results$(TargetFramework).trx</VSTestLogger>
45+
</PropertyGroup>
46+
</Project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using WebDriverManager.Helpers;
4+
using Architecture = WebDriverManager.Helpers.Architecture;
5+
6+
namespace WebDriverManager.DriverConfigs.Impl
7+
{
8+
public abstract class BaseChromeConfig : IDriverConfig
9+
{
10+
public abstract string GetLatestVersion();
11+
public abstract string GetMatchingBrowserVersion();
12+
protected abstract string GetUrl(Architecture architecture);
13+
14+
public virtual string GetName()
15+
{
16+
return "Chrome";
17+
}
18+
19+
public virtual string GetUrl32()
20+
{
21+
return GetUrl(Architecture.X32);
22+
}
23+
24+
public virtual string GetUrl64()
25+
{
26+
return GetUrl(Architecture.X64);
27+
}
28+
29+
public virtual string GetBinaryName()
30+
{
31+
var isWindows = true;
32+
#if NETSTANDARD
33+
isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
34+
#endif
35+
var suffix = isWindows ? ".exe" : string.Empty;
36+
return $"chromedriver{suffix}";
37+
}
38+
39+
protected string GetRawBrowserVersion()
40+
{
41+
#if NETSTANDARD
42+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
43+
{
44+
return RegistryHelper.GetInstalledBrowserVersionOsx("Google Chrome", "--version");
45+
}
46+
47+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
48+
{
49+
return RegistryHelper.GetInstalledBrowserVersionLinux(
50+
"google-chrome", "--product-version",
51+
"chromium", "--version",
52+
"chromium-browser", "--version",
53+
"chrome", "--product-version");
54+
}
55+
56+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
57+
{
58+
return RegistryHelper.GetInstalledBrowserVersionWin("chrome.exe");
59+
}
60+
61+
throw new PlatformNotSupportedException("Your operating system is not supported");
62+
#else
63+
return RegistryHelper.GetInstalledBrowserVersionWin("chrome.exe");
64+
#endif
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)