使用Safari 12时,会话未创建Selenium/webdriver [英] Session not created Selenium/webdriver when using Safari 12

查看:74
本文介绍了使用Safari 12时,会话未创建Selenium/webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从升级到Safari 12之后,我的自动化脚本现在出现此错误:

Since upgrading to Safari 12, my automated scripts are now getting this error:

SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.

(其他浏览器不会发生该错误).

(The error does not occur for other browsers).

我正在使用javascript webdriver绑定,并且在构建webdriver时,我使用了withCapability键值对:

I'm using the javascript webdriver bindings and, when I build webdriver, I use the withCapability key value pairs:

var capabs = {
       'browserName' : 'Safari',
       'version' : '12.0'
    }
    browserUnderTest = new webdriver.Builder().
    withCapabilities(capabs)    
    .forBrowser('safari')
    .build();

我认为问题出在safari.js文件本身,但是我对它如何精确定位任何东西还不了解.这是错误的全文:

I think the problem is with the safari.js file itself, but I don't know enough about how it operates to pinpoint anything. Here is the full text of the error:

SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.
    at Object.throwDecodedError (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/error.js:514:15)
    at parseHttpResponse (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:519:13)
    at doSend.then.response (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:441:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/safari.js:253:41)
    at createDriver (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:170:33)
    at Builder.build (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:660:16)
    at Object.<anonymous> (/Users/qualit/Documents/autotests/K8_autotest.js:354:6)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)

有人对这个原因或解决方法有任何想法吗?

Does anyone have any ideas about the cause of this or a fix?

推荐答案

之所以会发生此问题,是因为Safari 12使用了新的)不兼容使用最新的稳定的selenium-webdriver软件包(v3.6)

This issue happens because Safari 12 uses a new W3C webdriver protocol (source) which appears to be incompatible with the latest stable selenium-webdriver package (v3.6)

safaridriver传递--legacy标志以使用旧协议.直接在命令行上可以完成以下操作:/usr/bin/safaridriver --legacy

safaridriver can be passed a --legacy flag to use the old protocol. Directly on the command line this would be done like: /usr/bin/safaridriver --legacy

可以在节点程序中的驱动程序上设置此标志,如下所示:

This flag can be set on the driver in your node program as follows:

const webdriver = require('selenium-webdriver');
const safari = require('selenium-webdriver/safari');

new webdriver.Builder()
    .usingServer(await new safari.ServiceBuilder().addArguments('--legacy').build().start())
    .forBrowser('safari')
    .build();

有关ServiceBuilder API的文档-

Here's documentation on the ServiceBuilder API - https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/safari_exports_ServiceBuilder.html

一些GitHub票也涵盖了这一点:

A couple GitHub tickets cover this as well:

  • https://github.com/SeleniumHQ/selenium/issues/6431
  • https://github.com/SeleniumHQ/selenium/issues/6026

这篇关于使用Safari 12时,会话未创建Selenium/webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆