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

fix(browser): avoid safaridriver collision #4863

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Jan 3, 2024

Description

Fixes #4706.

Removes code from node/providers/webdriver.ts causing the following error when running vitest --browser.name=safari on macOS:

  Error: There is already a Safaridriver instance running on port
  undefined!

Cause

safaridriver.start() maintains a static reference to a safaridriver instance, and will fail with this error if start() is called again before stop().

The original node/providers/webdriver.ts calls safaridriver.start() directly, and then immediately imports and calls webdriverio.remote(). This call also eventually calls safaridriver.start(), producing the error.

The fix is to remove the direct safaridriver access, as webdriverio seems to manage safaridriver successfully now.

Testing

Since Safari can't run in headless mode, I couldn't think of a way to add a test that would run in CI. However, I added a new test:safaridriver target intended to be run manually as needed, which runs all the existing test/browser tests under Safari.

Enabling/documentation

Note that you have to enable automation in Safari via Developer > Allow remote automation, or else running with the safaridriver will fail with:

Error: Failed to create session.
Could not create a session: You must enable the 'Allow Remote 
Automation' option in Safari's Develop menu to control Safari via
WebDriver.

If it would be helpful to add a doc change for this, or to open a new PR for one, I'm happy to do that.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Removes code from node/providers/webdriver.ts causing the following
error when running `vitest --browser.name=safari` on macOS:

  Error: There is already a Safaridriver instance running on port
  undefined!

safaridriver.start() maintains a static reference to a safaridriver
instance, and will fail with this error if start() is called again
before stop().

The original node/providers/webdriver.ts calls safaridriver.start()
directly, and then immediately imports and calls webdriverio.remote().
This call also eventually calls safaridriver.start(), producing the
error.

The fix is to remove the direct safaridriver access, as webdriverio
seems to manage safaridriver successfully now.

---

Testing:

Since Safari can't run in headless mode, I couldn't think of a way to
add a test that would run in CI. However, I added a new
test:safaridriver target intended to be run manually as needed, which
runs all the existing test/browser tests under Safari.

---

One extra observation:

Command line options like --browser.headless=false are _not_ converted
to boolean values; they remain string values.

This is why the `--browser.headless` argument is now pushed onto the
extracted argv[], after I had originally tried updating the existing
argument string to:

  `--browser.headless=${browser !== 'safari'}`

When I updated the `pnpm:safaridriver` target with `PROVIDER=playwright`
to see what would happen (even though this is only a webdriver change),
it produced this error:

  Error: browserType.launch: headless: expected boolean, got string
	 ❯ PlaywrightBrowserProvider.openBrowserPage
     ../../packages/browser/dist/providers.js:22:52
       20|     const options = this.ctx.config.browser;
       21|     const playwright = await import('playwright');
			 22|     const browser = await playwright[this.browser].launch({
         |                                                    ^
       23|       ...this.options?.launch,
       24|       headless: options.headless

You can actually see this by running:

  npx vitest --run --browser.name=webkit --browser.provider=playwright
    --browser.headless=false

This seems like a bug worth filing, but not addressing in this change.
Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 86de156
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/6595d94e3b6dbc0008569b63

@sheremet-va sheremet-va merged commit 345a25d into vitest-dev:main Jan 4, 2024
19 checks passed
@mbland mbland deleted the fix-safaridriver branch January 4, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

safaridriver.start() conflicts with webdriverio.remote()
2 participants