microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.4k stars 3.63k forks source link

[BUG] playwright install doesn't install required browser version #9355

Closed c-kirkeby closed 3 years ago

c-kirkeby commented 3 years ago

Context:

Code Snippet

// global-setup.ts
import { chromium, PlaywrightTestConfig } from '@playwright/test'
import dotenv from 'dotenv'

async function globalSetup(config: PlaywrightTestConfig) {
  const { baseURL } = config.projects[0].use
  // Initialise environment variables
  dotenv.config();

  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto(baseURL);

  await page.waitForSelector('#okta-signin-username');
  await page.fill('#okta-signin-username', process.env.AUTH_USERNAME);
  await page.fill('#okta-signin-password', process.env.AUTH_PASSWORD);
  await page.click('#okta-signin-submit');
  await page.waitForNavigation(baseURL + '/dashboard');
  await page.context().storageState({ path: './tests/tmp/store_manager.json'});
  await page.close();
  await browser.close();
}

export default globalSetup;
// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test'
import dotenv from 'dotenv'

dotenv.config();

const config: PlaywrightTestConfig = {
  timeout: 60000,
  use: {
    baseURL: process.env.BASE_URL,
    bypassCSP: true,
    headless: true
  },
  globalSetup: require.resolve('./tests/global-setup')
};

export default config;

Describe the bug

When I try to run a simple spec (before it even gets to the spec) I get the following error:

$ playwright test
Using config at /home/christian/projects/playwright-test/playwright.config.ts
browserType.launch: Executable doesn't exist at /home/christian/.cache/ms-playwright/chromium-907428/chrome-linux/chrome
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers:              ║
║                                                                         ║
║     npx playwright install                                              ║
║                                                                         ║
║ <3 Playwright Team                                                      ║
╚═════════════════════════════════════════════════════════════════════════╝
    at globalSetup (/home/christian/projects/playwright-test/tests/global-setup.ts:9:34)
    at Runner._run (/home/christian/projects/playwright-test/node_modules/@playwright/test/lib/test/runner.js:205:125) {
  name: 'Error'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I run npx playwright install it doesn't seem to install the necessary browser and I receive no output. If I run npx playwright install chrome, it doesn't download the version that playwright is asking for and will yield the same error as above when I run playwright test:

❯ npx playwright install chrome
+ is_user_root
+ '[' 1000 -eq 0 ']'
+ maybesudo=sudo
+ grep -q '^google-chrome[[:space:]]*install$'
+ dpkg --get-selections
+ command -v wget
+ cd /tmp
+ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
--2021-10-07 17:07:16--  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Resolving dl.google.com (dl.google.com)... 142.250.66.174, 2404:6800:4006:80e::200e
Connecting to dl.google.com (dl.google.com)|142.250.66.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 90273096 (86M) [application/x-debian-package]
Saving to: 'google-chrome-stable_current_amd64.deb’

google-chrome-stable_current_amd64.deb             100%[===============================================================================================================>]  86.09M  6.01MB/s    in 15s     

2021-10-07 17:07:31 (5.85 MB/s) - 'google-chrome-stable_current_amd64.deb’ saved [90273096/90273096]

+ sudo apt-get install -y ./google-chrome-stable_current_amd64.deb
[sudo] password for christian: 
Sorry, try again.
[sudo] password for christian: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'google-chrome-stable' instead of './google-chrome-stable_current_amd64.deb'
google-chrome-stable is already the newest version (94.0.4606.71-1).
The following package was automatically installed and is no longer required:
  libllvm11
Use 'sudo apt autoremove' to remove it.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
+ rm -rf ./google-chrome-stable_current_amd64.deb
+ cd -
/home/christian/projects/playwright-test/node_modules/playwright/bin
+ google-chrome --version
Google Chrome 94.0.4606.71 

Is there a way to force playwright to download a specific version?

mxschmitt commented 3 years ago

Do you have playwright and @playwright/test installed? If so, you can remove playwright and execute npm ci and afterwards npx playwright install. Then it should work.

xiaokun commented 3 years ago

playwright install webkit-1516, but the nuget package 1.15.4 need webket-1550, the message when call IPlaywright.Webkit.LaunchAsync throw exception: Executable doesn't exist at C:\Users****\AppData\Local\ms-playwright\webkit-1550\Playwright.exe

mxschmitt commented 3 years ago

playwright install webkit-1516, but the nuget package 1.15.4 need webket-1550, the message when call IPlaywright.Webkit.LaunchAsync throw exception: Executable doesn't exist at C:\Users****\AppData\Local\ms-playwright\webkit-1550\Playwright.exe

Your issue is probably a different one. Did you follow this guide? https://playwright.dev/dotnet/docs/intro

yury-s commented 3 years ago

npx playwright install chrome installs chrome stable, you should either call npx playwright install as Max suggested above to install chromium (which is used by default) or modify your code to use Chrome stable channel:

inside globalSetup:

const browser = await chromium.launch({ channel: 'chrome' });

in the config:

const config: PlaywrightTestConfig = {
  timeout: 60000,
  use: {
    channel: 'chrome',
    ...
  },
};

channel: 'chrome'