Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion WebDriverManager.Tests/ChromeConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
using Xunit;

namespace WebDriverManager.Tests
{
public class ChromeConfigTests : ChromeConfig
public class ChromeConfigTests : ChromeConfig, IDisposable
{
private bool disposedValue;

[Fact]
public void VersionTest()
{
Expand All @@ -30,5 +34,49 @@ public void DriverDownloadTest()

Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
}


[Fact]
public void SpecificVersionDriverDownloadTest()
{
new DriverManager().SetUpDriver(new ChromeConfig(), "145.0.7632.117");

Assert.NotEmpty(WebDriverFinder.FindFile(GetBinaryName()));
}

/// <summary>
/// Cleanup after each test by deleting the downloaded file directory
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
try
{
if (Directory.Exists(WebDriverFinder.FindFile(GetBinaryName())))
{
var childDirectory = new DirectoryInfo(WebDriverFinder.FindFile(GetBinaryName()));
//Go to parent as child directory is the x64 directory
childDirectory.Parent.Delete(true);
}
}
catch (Exception)
{
// ignored - when run from container, we may not have access to delete the directory
}
}
disposedValue = true;
}
}

void IDisposable.Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
92 changes: 46 additions & 46 deletions WebDriverManager.Tests/WebDriverManager.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageReference Include="Selenium.WebDriver" Version="4.25.0" />
<PackageReference Include="xunit" Version="2.9.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebDriverManager\WebDriverManager.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Assets\file.txt" />
<Content Include="Assets\file.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Assets\removable.zip" />
<Content Include="Assets\removable.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Assets\unzipable.zip" />
<Content Include="Assets\unzipable.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<None Update="Assets\gzip.tar.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup>
<VSTestLogger>trx%3bLogFileName=Results$(TargetFramework).trx</VSTestLogger>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageReference Include="Selenium.WebDriver" Version="4.25.0" />
<PackageReference Include="xunit" Version="2.9.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebDriverManager\WebDriverManager.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="Assets\file.txt" />
<Content Include="Assets\file.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Assets\removable.zip" />
<Content Include="Assets\removable.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Assets\unzipable.zip" />
<Content Include="Assets\unzipable.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<None Update="Assets\gzip.tar.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<PropertyGroup>
<VSTestLogger>trx%3bLogFileName=Results$(TargetFramework).trx</VSTestLogger>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions WebDriverManager/DriverConfigs/IDriverConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface IDriverConfig
string GetBinaryName();
string GetLatestVersion();
string GetMatchingBrowserVersion();
string GetMatchingExplicitRequest(string version);
}
}
21 changes: 21 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/ChromeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ public virtual string GetMatchingBrowserVersion()
return _chromeVersion;
}

public virtual string GetMatchingExplicitRequest(string desiredVersion)
{
var chromeVersion = VersionHelper.GetVersionWithoutRevision(desiredVersion);

// Handle downloading versions of the chrome webdriver less than what's supported by the Chrome for Testing known good versions API
// See https://googlechromelabs.github.io/chrome-for-testing for more info
var matchedVersion = new Version(desiredVersion);
if (matchedVersion < MinChromeForTestingDriverVersion)
{
var url = ExactReleaseVersionPatternUrl.Replace("<version>", chromeVersion);
_chromeVersion = GetVersionFromChromeStorage(url);
}
else
{
_chromeVersion = GetVersionFromChromeForTestingApi(chromeVersion).Version;
}

return _chromeVersion;
}

/// <summary>
/// Retrieves a chrome driver version string from https://chromedriver.storage.googleapis.com
/// </summary>
Expand Down Expand Up @@ -236,5 +256,6 @@ private string GetRawBrowserVersion()
return RegistryHelper.GetInstalledBrowserVersionWin("chrome.exe");
#endif
}

}
}
6 changes: 6 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/EdgeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,11 @@ public string GetMatchingBrowserVersion()
return RegistryHelper.GetInstalledBrowserVersionWin("msedge.exe");
#endif
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}

}
}
5 changes: 5 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/FirefoxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public virtual string GetMatchingBrowserVersion()
#endif
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}

private static string GetUrl(Architecture architecture)
{
#if NETSTANDARD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -62,5 +62,11 @@ public virtual string GetMatchingBrowserVersion()
"svcVersion",
"Latest");
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}

}
}
5 changes: 5 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/LegacyEdgeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ public virtual string GetMatchingBrowserVersion()
{
throw new NotImplementedException();
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}
}
}
5 changes: 5 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/OperaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public virtual string GetMatchingBrowserVersion()
{
throw new NotImplementedException();
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}
}
}
5 changes: 5 additions & 0 deletions WebDriverManager/DriverConfigs/Impl/PhantomConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ public virtual string GetMatchingBrowserVersion()
{
throw new NotImplementedException();
}

public string GetMatchingExplicitRequest(string desiredVersion)
{
return desiredVersion;
}
}
}
2 changes: 1 addition & 1 deletion WebDriverManager/DriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static string GetVersionToDownload(IDriverConfig config, string version)
{
case VersionResolveStrategy.MatchingBrowser: return config.GetMatchingBrowserVersion();
case VersionResolveStrategy.Latest: return config.GetLatestVersion();
default: return version;
default: return config.GetMatchingExplicitRequest(version);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions WebDriverManager/Helpers/RegistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static string GetInstalledBrowserVersionWin(string executableFileName)

var currentUserPath = Microsoft.Win32.Registry.GetValue(
currentUserRegistryPathPattern.Replace("<executableFileName>", executableFileName), "", null);
//TODO: If Chromium is installed, that version is returned instead, skip if currentUserPath contains Chromium?
if (currentUserPath != null)
{
return FileVersionInfo.GetVersionInfo(currentUserPath.ToString()).FileVersion;
Expand Down