SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.5k stars 8.15k forks source link

Unable to run Safari Technology Preview with Selenium standalone server #6791

Closed cuki closed 3 years ago

cuki commented 5 years ago

🐛 Bug Report

According to this commit (6e09f51a5ff1debfe67e7fb1c5cbd21426c1c143) you should be able to switch between Safari and Safari Technology Preview by using the respective browser name ("Safari Technology Preview"). https://github.com/SeleniumHQ/selenium/blob/b62378814139566f6fcc4814d1243dd8b845eda0/java/client/src/org/openqa/selenium/safari/SafariOptions.java#L195

It seems whatever you specify as capabilities is discarded and reset upon creation of new SafariOptions instance: https://github.com/SeleniumHQ/selenium/blob/b62378814139566f6fcc4814d1243dd8b845eda0/java/client/src/org/openqa/selenium/safari/SafariOptions.java#L72-L75

Simply put, it does not respect the specified browserName value.

To Reproduce

  1. Enable safaridriver
    /usr/bin/safaridriver --enable
  2. Start Selenium standalone server
    selenium-standalone start
  3. Initiate new session with "Safari Technology Preview"
    curl -d '{ "capabilities": { "alwaysMatch": { "browserName": "Safari Technology Preview" }, "firstMatch": [ {} ] }, "desiredCapabilities": { "browserName": "Safari Technology Preview" } }' http://localhost:4444/wd/hub/session

Logs

org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "Safari Technology Preview"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "Safari Technology Preview"
      }
    ]
  }
}
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:22:52'
System info: host: 'MBP', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_131'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:76)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

Expected behavior

Upon specifying "Safari Technology Preview" as browserName when running Selenium standalone server, it should utilize the corresponding safaridriver executable located within the Technology Preview application.

Environment

OS: macOS High Sierra 10.13.6 Browser: Safari Browser version: Technology Preview release 72 (12.1, 13607.1.17.1) Browser Driver version: Language Bindings version: Standalone server 3.141.59

Additional context

As alternative there is the deprecated safari.options.technologyPreview (desired) capability which does work, however does not comply with W3C standard for capabilities, unlike the previously removed vendor-prefixed se:safari:techPreview capability.

This imposes a problem when using an implementation to communicate with Selenium, which has strict compliance with W3C standard (e.g. webdriverio) and/or does not allow you to specify desiredCapabilities different than capabilities.

titusfortner commented 4 years ago

fwiw, this is what I'm currently getting when passing in to the grid built from trunk:

2020-07-11 12:14:33 INFO Selenium -> POST session 2020-07-11 12:14:33 INFO Selenium >>> http://127.0.0.1:4445/wd/hub/session | {"capabilities":{"firstMatch":[{"browserName":"Safari Technology Preview","platformName":"mac"}]}} 2020-07-11 12:14:34 INFO Selenium <- { "value": { "error": "session not created", "message": "Unable to create session for \u003cCreateSessionRequest with Capabilities {browserName: Safari Technology Preview, platformName: mac}>\nBuild info: version: '4.0.0-alpha-7', revision: 'b93eab6f3a*'\nSystem info: host: 'SL-1495.local', ip: '2601:1c0:5200:2640:0:0:0:89cf%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.5', java.version: '11.0.6'\nDriver info: driver.version: unknown",

shs96c commented 4 years ago

So, this boils down to the way that we configure the server. Right now, the LocalNodeFactory is the place where things get wired up. This looks up every instance of DriverService.Builder via ServiceLoader. By default, the Safari implementation of this uses the regular Safari and not the Tech Preview.

We have two choices:

  1. Break out two instances of the builder, one for Safari, and one for the Tech Preview
  2. Change how we wire up the node in the first place, and use some kind of Function<Capabilities, WebDriver> instead of what we're doing now.

I think the second is neater, but the first is a lot easier to do :)

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.