Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Chrome for Testing #192

Merged
merged 2 commits into from
Jul 26, 2023
Merged
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
28 changes: 24 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, ubuntu-20.04, macos-latest, macos-11 ]
branch: [ 'master', 'now' ]
branch:
# - 'master'
- 'now'
chrome_version:
- 'current'
- '114.0.5735.90'
steps:
- uses: actions/checkout@v3
- if: startsWith(matrix.os, 'ubuntu')
Expand All @@ -37,9 +42,22 @@ jobs:
node_modules/.bin/tsc $GITHUB_WORKSPACE/__tests__/chromedriver.ts
node_modules/.bin/ncc build $GITHUB_WORKSPACE/__tests__/chromedriver.js -o $GITHUB_WORKSPACE/__tests__
rm -rf node_modules
- run: |
CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ' | cut -d '.' -f 1)
- if: matrix.chrome_version != 'current'
env:
CHROME_VERSION: ${{ matrix.chrome_version }}
run: |
CHROME_VERSION=$(echo $CHROME_VERSION | cut -d '.' -f 1)
echo "CHROMEDRIVER_VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION})" >> $GITHUB_ENV
- if: matrix.chrome_version == 'current' && startsWith(matrix.os, 'ubuntu')
run: |
CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ')
echo "CHROMEDRIVER_VERSION=$CHROME_VERSION" >> $GITHUB_ENV
- if: matrix.chrome_version == 'current' && startsWith(matrix.os, 'maos')
env:
CHROME_VERSION: '114.0.5735.90'
run: |
CHROME_VERSION=$(echo $CHROME_VERSION | cut -d '.' -f 1)
echo "CHROMEDRIVER_VERSION=$CHROME_VERSION" >> $GITHUB_ENV
- uses: ./
if: matrix.branch == 'now'
with:
Expand All @@ -61,7 +79,9 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, ubuntu-20.04, macos-latest, macos-11 ]
branch: [ 'master', 'now' ]
branch:
# - 'master'
- 'now'
steps:
- uses: actions/checkout@v3
- if: startsWith(matrix.os, 'ubuntu')
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ jobs:
run: |
$chrome_fullversion = (Get-Item $Env:CHROMEAPP).VersionInfo.FileVersion
$chrome_majorversion = $chrome_fullversion.Split(".")[0]
$response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion"
$version = $response.Content
echo "CHROMEDRIVER_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
if($chrome_majorversion -lt 115)
{
$response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion"
$version = $response.Content
echo "CHROMEDRIVER_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
}
else
{
echo "CHROMEDRIVER_VERSION=$chrome_fullversion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
}
- uses: ./
if: matrix.branch == 'now'
with:
Expand Down
33 changes: 27 additions & 6 deletions lib/setup-chromedriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@ Param(
[string]$version
)

$chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion

Write-Output "Chrome version: $chrome_fullversion"
if([string]::IsNullOrEmpty($version))
{
$chrome_fullversion = (Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion
$chrome_majorversion = $chrome_fullversion.Split(".")[0]
}
else
{
$chrome_majorversion = $version.Split(".")[0]
}
if($chrome_majorversion -lt 115)
{
$response = Invoke-WebRequest "http://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chrome_majorversion"
$version = $response.Content
Invoke-WebRequest "https://chromedriver.storage.googleapis.com/$version/chromedriver_win32.zip" -OutFile chromedriver_win32.zip
Expand-Archive -Path chromedriver_win32.zip -DestinationPath C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver_win32.zip
}
else
{
if([string]::IsNullOrEmpty($version))
{
$version = $chrome_fullversion
}
$arch = "win32"
Write-Output $arch
$url = Invoke-WebRequest "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json" -UseBasicParsing | ConvertFrom-Json | Select-Object -ExpandProperty versions | Where-Object { $_.version -eq $version } | Select-Object -ExpandProperty downloads | Select-Object -ExpandProperty chromedriver | Where-Object { $_.platform -eq $arch } | Select-Object -ExpandProperty url
Invoke-WebRequest $url -OutFile chromedriver-win32.zip
Expand-Archive -Path chromedriver-win32.zip -Force
Move-Item -Path .\chromedriver-win32\chromedriver-win32\chromedriver.exe -Destination C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver-win32.zip
}

Invoke-WebRequest "https://chromedriver.storage.googleapis.com/$version/chromedriver_win32.zip" -OutFile chromedriver_win32.zip

Expand-Archive -Path chromedriver_win32.zip -DestinationPath C:\SeleniumWebDrivers\ChromeDriver -Force
Remove-Item chromedriver_win32.zip
56 changes: 51 additions & 5 deletions lib/setup-chromedriver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,66 @@ ARCH=$2

if [ "$ARCH" == "linux64" ]; then
CHROMEAPP=google-chrome
if ! type -a sudo > /dev/null 2>&1; then
apt-get update
apt-get install -y sudo
fi
if ! type -a curl > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y curl
fi
if ! type -a google-chrome > /dev/null 2>&1; then
# for debian
# curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64f.deb
# sudo apt install -y ./google-chrome-stable_current_amd64.deb
# CHROMEAPP=google-chrome-stable
sudo apt-get update
sudo apt-get install -y google-chrome
fi
if ! type -a jq > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y jq
fi
if ! type -a bc > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y bc
fi
elif [ "$ARCH" == "mac64" ]; then
CHROMEAPP="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
fi

if [ "$VERSION" == "" ]; then
CHROME_VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ' | cut -d '.' -f 1)
VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION})
else
CHROME_VERSION=$(echo "$VERSION" | cut -d '.' -f 1)
fi

wget -c -nc --retry-connrefused --tries=0 https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip
unzip -o -q chromedriver_${ARCH}.zip
sudo mv chromedriver /usr/local/bin/chromedriver
rm chromedriver_${ARCH}.zip
UNDER115=$(echo "$CHROME_VERSION < 115" | bc)
if [ "$UNDER115" -eq 1 ]; then
if [ "$VERSION" == "" ]; then
VERSION=$(curl --location --fail --retry 10 http://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION})
fi
echo "Installing ChromeDriver $VERSION for $ARCH"

curl --location --fail --retry 10 -O https://chromedriver.storage.googleapis.com/${VERSION}/chromedriver_${ARCH}.zip
unzip -o -q chromedriver_${ARCH}.zip
rm chromedriver_${ARCH}.zip
else
if [ "$VERSION" == "" ]; then
VERSION=$("$CHROMEAPP" --version | cut -f 3 -d ' ')
fi
if [ "$ARCH" == "mac64" ]; then
ARCH="mac-x64"
fi

echo "Installing ChromeDriver $VERSION for $ARCH"
URL=$(curl --location --fail --retry 10 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq -r ".versions[] | select(.version == \"${VERSION}\") | .downloads.chromedriver[] | select(.platform == \"${ARCH}\") | .url")
echo "Downloading $URL"
curl --location --fail --retry 10 -O "$URL"
unzip -o -q chromedriver-${ARCH}.zip
sudo mv chromedriver-${ARCH}/chromedriver /usr/local/bin/chromedriver
rm chromedriver-${ARCH}.zip
rm -r chromedriver-${ARCH}
fi