Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat: support `npx playwright install chrome` (#6835)

Andrey Lushnikov919d258356f8
diff --git a/.github/workflows/tests_secondary.yml b/.github/workflows/tests_secondary.yml
index 8f49b6ef44..ad923734de 100644
--- a/.github/workflows/tests_secondary.yml
+++ b/.github/workflows/tests_secondary.yml
@@ -199,15 +199,12 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: 12
- - name: Install Chrome Stable
- run: sudo apt install google-chrome-stable
- run: npm ci
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: node lib/cli/cli install-deps chromium
- # This only created problems, should we move ffmpeg back into npm?
- - run: node lib/cli/cli install ffmpeg
+ - run: node lib/cli/cli install chrome
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
# Wrap `npm run` in a subshell to redirect STDERR to file.
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "npm run ctest"
@@ -236,8 +233,7 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- # This only created problems, should we move ffmpeg back into npm?
- - run: node lib/cli/cli install ffmpeg
+ - run: node lib/cli/cli install chrome
- run: npm run ctest
shell: bash
env:
@@ -263,8 +259,7 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- # This only created problems, should we move ffmpeg back into npm?
- - run: node lib/cli/cli install ffmpeg
+ - run: node lib/cli/cli install chrome
- run: npm run ctest
env:
PWTEST_CHANNEL: chrome
@@ -289,7 +284,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: node lib/cli/cli install-deps firefox
- - run: node lib/cli/cli install ffmpeg firefox-stable chromium
+ - run: node lib/cli/cli install firefox-stable chromium
# XVFB-RUN merges both STDOUT and STDERR, whereas we need only STDERR
# Wrap `npm run` in a subshell to redirect STDERR to file.
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "npm run ftest"
@@ -318,7 +313,7 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- - run: node lib/cli/cli install ffmpeg firefox-stable chromium
+ - run: node lib/cli/cli install firefox-stable chromium
- run: npm run ftest
shell: bash
env:
@@ -344,7 +339,7 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- - run: node lib/cli/cli install ffmpeg firefox-stable chromium
+ - run: node lib/cli/cli install firefox-stable chromium
- run: npm run ftest
env:
PWTEST_CHANNEL: firefox-stable
@@ -371,7 +366,6 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- # This only created problems, should we move ffmpeg back into npm?
- run: node lib/cli/cli install ffmpeg
- run: npm run ctest
shell: bash
diff --git a/bin/reinstall_chrome_beta_linux.sh b/bin/reinstall_chrome_beta_linux.sh
index ab08cf6eb1..bf43df3648 100755
--- a/bin/reinstall_chrome_beta_linux.sh
+++ b/bin/reinstall_chrome_beta_linux.sh
@@ -3,7 +3,7 @@ set -e
set -x
# 1. make sure to remove old beta if any.
-if sudo dpkg -S google-chrome-beta &>/dev/null; then
+if dpkg --get-selections | grep -q "^google-chrome-beta[[:space:]]*install$" >/dev/null; then
sudo apt-get remove -y google-chrome-beta
fi
diff --git a/bin/reinstall_chrome_stable_linux.sh b/bin/reinstall_chrome_stable_linux.sh
new file mode 100755
index 0000000000..b2c076d381
--- /dev/null
+++ b/bin/reinstall_chrome_stable_linux.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+set -e
+set -x
+
+# 1. make sure to remove old stable if any.
+if dpkg --get-selections | grep -q "^google-chrome[[:space:]]*install$" >/dev/null; then
+ sudo apt-get remove -y google-chrome
+fi
+
+
+# 2. download chrome stable from dl.google.com and install it.
+cd /tmp
+wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
+sudo apt-get install -y ./google-chrome-stable_current_amd64.deb
+rm -rf ./google-chrome-stable_current_amd64.deb
+cd -
diff --git a/bin/reinstall_chrome_stable_mac.sh b/bin/reinstall_chrome_stable_mac.sh
new file mode 100755
index 0000000000..6e48424f83
--- /dev/null
+++ b/bin/reinstall_chrome_stable_mac.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+set -x
+
+rm -rf "/Applications/Google Chrome.app"
+cd /tmp
+curl -o ./googlechrome.dmg -k https://dl.google.com/chrome/mac/beta/googlechrome.dmg
+hdiutil attach -nobrowse -quiet -noautofsck -noautoopen -mountpoint /Volumes/googlechrome.dmg ./googlechrome.dmg
+cp -rf "/Volumes/googlechrome.dmg/Google Chrome.app" /Applications
+hdiutil detach /Volumes/googlechrome.dmg
diff --git a/bin/reinstall_chrome_stable_win.ps1 b/bin/reinstall_chrome_stable_win.ps1
new file mode 100644
index 0000000000..9002b7cfa9
--- /dev/null
+++ b/bin/reinstall_chrome_stable_win.ps1
@@ -0,0 +1,20 @@
+$url = 'https://dl.google.com/tag/s/dl/chrome/install/beta/googlechromestandaloneenterprise.msi';
+
+if ([Environment]::Is64BitProcess) {
+ $url = 'https://dl.google.com/tag/s/dl/chrome/install/beta/googlechromestandaloneenterprise64.msi'
+}
+
+$app = Get-WmiObject -Class Win32_Product | Where-Object {
+ $_.Name -eq "Google Chrome"
+}
+if ($app) {
+ $app.Uninstall()
+}
+
+$wc = New-Object net.webclient
+$msiInstaller = "$env:temp\google-chrome.msi"
+Remove-Item $msiInstaller
+$wc.Downloadfile($url, $msiInstaller)
+
+$arguments = "/i `"$msiInstaller`" /quiet"
+Start-Process msiexec.exe -ArgumentList $arguments -Wait
diff --git a/src/cli/cli.ts b/src/cli/cli.ts
index e2408945c8..f02afd2f1b 100755
--- a/src/cli/cli.ts
+++ b/src/cli/cli.ts
@@ -39,8 +39,8 @@ import * as utils from '../utils/utils';
const SCRIPTS_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
-type BrowserChannel = 'chrome-beta';
-const allBrowserChannels: Set<BrowserChannel> = new Set(['chrome-beta']);
+type BrowserChannel = 'chrome-beta'|'chrome';
+const allBrowserChannels: Set<BrowserChannel> = new Set(['chrome-beta', 'chrome']);
program
.version('Version ' + require('../../package.json').version)
@@ -106,13 +106,13 @@ program
console.log(`Invalid installation targets: ${faultyArguments.map(name => `'${name}'`).join(', ')}. Expecting one of: ${[...allBrowserNames, ...allBrowserChannels].map(name => `'${name}'`).join(', ')}`);
process.exit(1);
}
- if (browserNames.has('chromium') || browserChannels.has('chrome-beta'))
+ if (browserNames.has('chromium') || browserChannels.has('chrome-beta') || browserChannels.has('chrome'))
browserNames.add('ffmpeg');
if (browserNames.size)
await installBrowsers([...browserNames]);
for (const browserChannel of browserChannels) {
- if (browserChannel === 'chrome-beta')
- await installChromeBeta();
+ if (browserChannel === 'chrome-beta' || browserChannel === 'chrome')
+ await installChromeChannel(browserChannel);
else
throw new Error(`ERROR: no installation instructions for '${browserChannel}' channel.`);
}
@@ -122,18 +122,25 @@ program
}
});
-async function installChromeBeta() {
+async function installChromeChannel(channel: string) {
const platform: string = os.platform();
const shell: (string|undefined) = {
'linux': 'bash',
'darwin': 'bash',
'win32': 'powershell.exe',
}[platform];
- const scriptName: (string|undefined) = {
- 'linux': 'reinstall_chrome_beta_linux.sh',
- 'darwin': 'reinstall_chrome_beta_mac.sh',
- 'win32': 'reinstall_chrome_beta_win.ps1',
- }[platform];
+ const scriptName: (string|undefined) = ({
+ 'chrome-beta': {
+ 'linux': 'reinstall_chrome_beta_linux.sh',
+ 'darwin': 'reinstall_chrome_beta_mac.sh',
+ 'win32': 'reinstall_chrome_beta_win.ps1',
+ },
+ 'chrome': {
+ 'linux': 'reinstall_chrome_stable_linux.sh',
+ 'darwin': 'reinstall_chrome_stable_mac.sh',
+ 'win32': 'reinstall_chrome_stable_win.ps1',
+ },
+ }[channel] as any)[platform];
if (!shell || !scriptName)
throw new Error(`Cannot install chrome-beta on ${platform}`);