Failed to connect to SafariDriver (Safari 10)

2019-02-10 02:56发布

I'm getting the following error when running my protractor test on mac for safari

Failed to connect to SafariDriver after 10082 ms
Build info: version: '2.53.1', revision: 'a36b8b1',     
os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_101'
Driver info: driver.version: SafariDriver

capability:

        name: 'Safari',
        browserName: 'safari',
        logName: 'Safari',
        shardTestFiles: true,
        maxInstances: 2

Do we need a specific safari driver for this? If yes, where can I get it from and where should it be declared in the .conf file.

Thank you!

2条回答
三岁会撩人
2楼-- · 2019-02-10 03:10

Yes, you need to install a specific safari driver in order to launch it inside of protractor. And of course, you need to be on a mac. Protractor is essentially a layer built on top of Selenium, so you need to install the selenium driver for Safari, which is implemented as a Safari plugin.

Here is what you need to do:

  1. Download the safari plugin from here.
  2. Run the plugin
  3. Select "Trust" the plugin when prompted by safari

The driver is now installed and should be available to your protractor process.

This is the driver for Selenium 2.48. I couldn't find a more recent build, so if this driver version doesn't run with the current version of Protractor, you will need to either use an older version of protractor that is based on Selenium 2.48 or build the safari driver from source.

查看更多
狗以群分
3楼-- · 2019-02-10 03:22

First of all, starting with Safari 10, Safari comes bundled with a new driver implementation. The old driver (the extension) is deprecated. You're using macOS 10.12.2, so it's your case. To enable the new driver in Safari, toggle the Allow Remote Automation checkbox in the Develop menu. If you don't have this menu, enable it: Preferences > Advanced > Show Develop menu in menu bar. Start /usr/bin/safaridriver once manually to grant it the permissions needed.

Secondly, you need a 3.x version of the Selenium Standalone Server, not 2.53.1. The command to install it:

sudo webdriver-manager update --versions.standalone 3.0.1

To start:

webdriver-manager start --versions.standalone 3.0.1

Thirdly, the visibility checks are broken in the new driver. So things like browser.wait(ExpectedConditions.visibilityOf(myElement), 5000); don't work and lead to UnsupportedCommandException. In order to fix this, you can try installing Safari Technology Preview and running tests there (add 'safari.options': { technologyPreview: true } to the capabilities). But for me, the preview works even worse than the release. Protractor says it can't find Angular on the page because they changed window.name to be cleared after a cross-origin navigation in the Release 19. If you happen to find a way to make it work, please let me know.

Below are some links you should check because I might have missed something.

查看更多
登录 后发表回答