Skip to content

Commit

Permalink
Include Gecko Driver for Apple M1
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakamoto committed May 28, 2022
1 parent ad44896 commit 7e9d560
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.src": "xml"
}
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NuGet package restoring ready, and no need to commit "geckodriver(.exe)" binary

For example, at the package manager console on Visual Studio, enter the following command.

PM> Install-Package Selenium.WebDriver.GeckoDriver -Version 0.31.0
PM> Install-Package Selenium.WebDriver.GeckoDriver -Version 0.31.0.1

## Cross-platform building and publishing

Expand All @@ -24,7 +24,8 @@ By default, the platform type of the web driver file copied to the output folder

- When you build the project which references the NuGet package of geckodriver **on 32bit Windows OS**, **win32 version** of geckodriver will be copied to the output folder.
- When you build the project which references the NuGet package of geckodriver **on 64bit Windows OS**, **win64 version** of geckodriver will be copied to the output folder.
- When you build it **on macOS**, **macOS x64 version** of geckodriver will be copied to the output folder.
- When you build it **on macOS on Intel CPU hardware**, **macOS x64 version** of geckodriver will be copied to the output folder.
- When you build it **on macOS on Apple CPU hardware**, **macOS Arm64 version** of geckodriver will be copied to the output folder.
- When you build it on **any Linux distributions**, **Linux x64 version** of geckodriver will be copied to the output folder.

### Method 1 - Specify "Runtime Identifier"
Expand All @@ -47,7 +48,8 @@ or, as a command-line `-r` option for dotnet build command.

- When the RID that **starts with "win"** and **contains "x86"** is specified, **win32 version** of geckodriver will be copied to the output folder.
- When the RID that **starts with "win"** and **contains "x64"** is specified, **win64 version** of geckodriver will be copied to the output folder.
- When the RID that **starts with "osx"** is specified, **macOS x64 version** of geckodriver will be copied to the output folder.
- When the RID that **starts with "osx"** and **ends with "x64"** is specified, **macOS x64 version** of geckodriver will be copied to the output folder.
- When the RID that **starts with "osx"** and **ends with "arm64"** is specified, **macOS Arm64 version** of geckodriver will be copied to the output folder.
- When the RID that **starts with "linux"** is specified, **Linux x64 version** of geckodriver will be copied to the output folder.

If you specify another pattern of RID like "ubuntu.18.04-x64", the platform type of the web driver file which will be copied to the output folder depends on the OS running the build process. (default behavior.)
Expand All @@ -61,6 +63,7 @@ You can control which platform version of geckodriver will be copied by specifyi
- "win32"
- "win64"
- "mac64"
- "mac64arm"
- "linux64"

You can specify "GeckoDriverPlatform" MSBuild property in a project file,
Expand Down Expand Up @@ -136,6 +139,8 @@ folder.
| | +-- geckodriver.exe
| | +-- mac64
| | +-- geckodriver
| | +-- mac64arm
| | +-- geckodriver
| | +-- linux64
| | +-- geckodriver
| +-- build/
Expand Down
3 changes: 3 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v.0.31.0.1
- Include Gecko Driver for Apple M1

v.0.31.0
- Gecko Driver 0.31.0 release

Expand Down
4 changes: 2 additions & 2 deletions TestDrives/TestDrive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.31.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.2.0" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.31.0.1" />
</ItemGroup>
</Project>
31 changes: 22 additions & 9 deletions buildTools/download-driver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@ $downloadUrlBase = "https://github.com/mozilla/geckodriver/releases/download"
$drivers = @(
[ordered]@{
platform = "win32";
folder = "win32";
fileName = "geckodriver.exe";
archiveType = "zip";
}
,
[ordered]@{
platform = "win64";
folder = "win64";
fileName = "geckodriver.exe";
archiveType = "zip";
}
,
[ordered]@{
platform = "macos";
folder = "mac64";
fileName = "geckodriver";
archiveType = "tar.gz";
}
,
[ordered]@{
platform = "macos-aarch64";
folder = "mac64arm";
fileName = "geckodriver";
archiveType = "tar.gz";
}
,
[ordered]@{
platform = "linux64";
folder = "linux64";
fileName = "geckodriver";
archiveType = "tar.gz";
}
Expand All @@ -48,18 +59,20 @@ $drivers | ForEach-Object {
$driver = $_
$driverName = $driver.fileName
$platform = $driver.platform
$folder = $driver.folder
$archiveType = $driver.archiveType

$downloadDir = Join-Path $downloadsBaseDir $platform
$downloadDir = Join-Path $downloadsBaseDir $folder
$driverPath = Join-Path $downloadDir $driverName

# download driver .zip/.tar.gz file if not exists.
$zipName = "geckodriver-v$version-$platform.$archiveType"
$zipPath = Join-Path $downloadDir $zipName
if (-not (Test-Path $zipPath)) {
$downloadUrl = "$downloadUrlBase/v$version/$zipName"
$archiveName = "geckodriver-v$version-$platform.$archiveType"
$archivePath = Join-Path $downloadDir $archiveName
if (-not (Test-Path $downloadDir)) { mkdir $downloadDir > $null }
if (-not (Test-Path $archivePath)) {
$downloadUrl = "$downloadUrlBase/v$version/$archiveName"
Write-Host $downloadUrl
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath
if (Test-Path $driverPath) {
Remove-Item $driverPath
}
Expand All @@ -69,11 +82,11 @@ $drivers | ForEach-Object {
if (-not (Test-Path $driverPath)) {
Set-Location $downloadDir
if ($archiveType -eq "zip") {
& $unzip -q $zipName
& $unzip -q $archiveName
}
if ($archiveType -eq "tar.gz") {
& $gzip -kdf $zipName
& $tar -xf ((Get-ChildItem $zipName).BaseName)
& $gzip -kdf $archiveName
& $tar -xf ((Get-ChildItem $archiveName).BaseName)
}
Set-Location $currentPath
}
Expand Down
Empty file removed downloads/macos/.gitkeep
Empty file.
6 changes: 4 additions & 2 deletions src/DefinePropertiesGeckoDriver.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<PropertyGroup>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;win&quot;))'=='True' And '$(RuntimeIdentifier.Contains(&quot;x86&quot;))'=='True' ">win32</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;win&quot;))'=='True' And '$(RuntimeIdentifier.Contains(&quot;x64&quot;))'=='True' ">win64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' And '$(RuntimeIdentifier.EndsWith(&quot;arm64&quot;))'=='False' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' And '$(RuntimeIdentifier.EndsWith(&quot;arm64&quot;))'=='True' ">mac64arm</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;linux&quot;))'=='True' ">linux64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Windows_NT' And Exists ('$(windir)\SysWOW64')">win64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Windows_NT'">win32</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64' ">mac64arm</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' ">linux64</GeckoDriverPlatform>
</PropertyGroup>

Expand Down
15 changes: 8 additions & 7 deletions src/Selenium.WebDriver.GeckoDriver.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Selenium.WebDriver.GeckoDriver</id>
<title>Selenium.WebDriver.GeckoDriver (Win32, Win64, macOS, and Linux64)</title>
<version>0.31.0</version>
<title>Selenium.WebDriver.GeckoDriver (Win32, Win64, macOS, macOS M1, and Linux64)</title>
<version>0.31.0.1</version>
<authors>jsakamoto</authors>
<summary>Selenium Gecko Driver (Win32, Win64, macOS, and Linux64) (does not make your source repository too fat.)</summary>
<summary>Selenium Gecko Driver (Win32, Win64, macOS, macOS M1, and Linux64) (does not make your source repository too fat.)</summary>
<description>
Install Gecko Driver (Win32, Win64, macOS, and Linux64) for Selenium WebDriver into your Unit Test Project.
Install Gecko Driver (Win32, Win64, macOS, macOS M1, and Linux64) for Selenium WebDriver into your Unit Test Project.
"geckodriver(.exe)" is copied to bin folder from package folder when the build process.
NuGet package restoring ready, and no need to commit "geckodriver(.exe)" binary into source code control repository.
/ The MSBuild script that contained this package is free and unencumbered software released into the public domain.
Expand All @@ -22,15 +22,16 @@
<readme>README.md</readme>
<releaseNotes>
<![CDATA[
v.0.31.0
- Gecko Driver 0.31.0 release
v.0.31.0.1
- Include Gecko Driver for Apple M1
]]>
</releaseNotes>
</metadata>
<files>
<file src="..\downloads\win32\geckodriver.exe" target="driver/win32" />
<file src="..\downloads\win64\geckodriver.exe" target="driver/win64" />
<file src="..\downloads\macos\geckodriver" target="driver/mac64/geckodriver" />
<file src="..\downloads\mac64\geckodriver" target="driver/mac64/geckodriver" />
<file src="..\downloads\mac64arm\geckodriver" target="driver/mac64arm/geckodriver" />
<file src="..\downloads\linux64\geckodriver" target="driver/linux64/geckodriver" />
<file src="Selenium.WebDriver.GeckoDriver.targets" target="build" />
<file src="DefinePropertiesGeckoDriver.targets" target="build" />
Expand Down
8 changes: 5 additions & 3 deletions src/Selenium.WebDriver.GeckoDriver.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
<PropertyGroup>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;win&quot;))'=='True' And '$(RuntimeIdentifier.Contains(&quot;x86&quot;))'=='True' ">win32</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;win&quot;))'=='True' And '$(RuntimeIdentifier.Contains(&quot;x64&quot;))'=='True' ">win64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' And '$(RuntimeIdentifier.EndsWith(&quot;arm64&quot;))'=='False' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;osx&quot;))'=='True' And '$(RuntimeIdentifier.EndsWith(&quot;arm64&quot;))'=='True' ">mac64arm</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(RuntimeIdentifier.StartsWith(&quot;linux&quot;))'=='True' ">linux64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Windows_NT' And Exists ('$(windir)\SysWOW64')">win64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Windows_NT'">win32</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64' ">mac64</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' And Exists ('/Applications') And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64' ">mac64arm</GeckoDriverPlatform>
<GeckoDriverPlatform Condition=" '$(GeckoDriverPlatform)' == '' And '$(OS)' == 'Unix' ">linux64</GeckoDriverPlatform>
</PropertyGroup>

Expand Down Expand Up @@ -83,7 +85,7 @@
</Target>

<Target Name="ChmodGeckoDriver" BeforeTargets="BeforeBuild">
<Exec Command="chmod +x &quot;$(GeckoDriverSrcPath)&quot;" Condition=" '$(OS)' != 'Windows_NT' AND ('$(GeckoDriverPlatform)' == 'mac64' Or '$(GeckoDriverPlatform)' == 'linux64') "/>
<Exec Command="chmod +x &quot;$(GeckoDriverSrcPath)&quot;" Condition=" '$(OS)' != 'Windows_NT' AND '$(GeckoDriverPlatform)' != 'win32' AND '$(GeckoDriverPlatform)' != 'win64' " />
</Target>

<!-- If publishing driver file is disabled (it's default behavior), define "copy" and "clean" build task. -->
Expand Down
4 changes: 2 additions & 2 deletions src/Selenium.WebDriver.GeckoDriver.targets.src
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</Target>

<Target Name="ChmodGeckoDriver" BeforeTargets="BeforeBuild">
<Exec Command="chmod +x &quot;$(GeckoDriverSrcPath)&quot;" Condition=" '$(OS)' != 'Windows_NT' AND ('$(GeckoDriverPlatform)' == 'mac64' Or '$(GeckoDriverPlatform)' == 'linux64') "/>
<Exec Command="chmod +x &quot;$(GeckoDriverSrcPath)&quot;" Condition=" '$(OS)' != 'Windows_NT' AND '$(GeckoDriverPlatform)' != 'win32' AND '$(GeckoDriverPlatform)' != 'win64' " />
</Target>

<!-- If publishing driver file is disabled (it's default behavior), define "copy" and "clean" build task. -->
Expand All @@ -35,4 +35,4 @@
<Target Name="DeleteGeckoDriverFromBin" BeforeTargets="AfterClean" Condition="'$(PublishGeckoDriver)' == 'false'">
<Delete Files="$(GeckoDriverTargetDir)$(GeckoDriverName)"></Delete>
</Target>
</Project>
</Project>
4 changes: 2 additions & 2 deletions test/Project/project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Selenium.WebDriver" Version="4.0.1" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.31.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.2.0" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.31.0.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions test/ProjectAB/ProjectA/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Selenium.WebDriver" version="3.141.0" targetFramework="net472" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.31.0" targetFramework="net472" />
<package id="Selenium.WebDriver" version="4.2.0" targetFramework="net472" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.31.0.1" targetFramework="net472" />
</packages>
5 changes: 3 additions & 2 deletions test/ProjectAB/ProjectA/program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using OpenQA.Selenium;

class Program
{
Expand All @@ -7,8 +8,8 @@ static void Main()
using (var driver = new OpenQA.Selenium.Firefox.FirefoxDriver(AppDomain.CurrentDomain.BaseDirectory))
{
driver.Navigate().GoToUrl("https://www.bing.com/");
driver.FindElementById("sb_form_q").SendKeys("Selenium WebDriver");
driver.FindElementById("sb_form_go").Click();
driver.FindElement(By.Id("sb_form_q")).SendKeys("Selenium WebDriver");
driver.FindElement(By.Id("sb_form_go")).Click();

Console.WriteLine("OK");
Console.ReadKey(intercept: true);
Expand Down
8 changes: 4 additions & 4 deletions test/ProjectAB/ProjectA/projectA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver, Version=3.141.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.141.0\lib\net45\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.4.2.0\lib\net47\WebDriver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -56,11 +56,11 @@
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.31.0\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.31.0\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.31.0.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.31.0.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.31.0\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.31.0\build\Selenium.WebDriver.GeckoDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.31.0.1\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.31.0.1\build\Selenium.WebDriver.GeckoDriver.targets'))" />
</Target>
</Project>
4 changes: 2 additions & 2 deletions test/Selenium.WebDriver.GeckoDriver.NuPkg.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

<ItemGroup>
<PackageReference Include="ChainingAssertion-NUnit.Bin" Version="1.8.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Toolbelt.WorkDirectory" Version="1.0.0" />
<PackageReference Include="XProcess" Version="1.2.0" />
<PackageReference Include="XProcess" Version="1.3.0" />
<PackageReference Include="Toolbelt.ExecutableFileFormatDetector" Version="1.0.0" />
</ItemGroup>

Expand Down

0 comments on commit 7e9d560

Please sign in to comment.