量角器 W3C 功能 [英] Protractor W3C capability

查看:62
本文介绍了量角器 W3C 功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ProtractorSelenoid.我需要使用 dockerized Windows 映像,以便我可以在 Linux 机器上测试 Internet Explorer 和 Edge.

I am using Protractor with Selenoid. I need to use the dockerized Windows images so that I can test Internet Explorer and Edge from Linux boxes.

我能够通过运行使其从 curl 工作:

I was able to make it work from curl by running:

curl -X POST http://127.0.0.1:4444/wd/hub/session -d '{"capabilities":{"browserName":"MicrosoftEdge","count":1,"alwaysMatch":{"browserName":"MicrosoftEdge","selenoid:options":{"enableVNC":true,"enableVideo":false,"enableLog":true,"logName":"edge-18.0.log"}}}}'

我的量角器配置如下:

  multiCapabilities: [
    {
      browserName: "MicrosoftEdge",
      "alwaysMatch": {
        browserName: "MicrosoftEdge",
        "selenoid:options": {
          enableVNC: true,
          enableVideo: false,
          enableLog: true,
          logName: "edge-18.0.log"
        }
      }
    }
  ]

但是 protractor 像这样通过 selenoid 服务器发送它:

But protractor send it over the selenoid server like this:

{
    "desiredCapabilities": {
        "browserName": "MicrosoftEdge",
        "count": 1,
        "alwaysMatch": {
            "browserName": "MicrosoftEdge",
            "selenoid:options": {
                "enableVNC": true,
                "enableVideo": false,
                "enableLog": true,
                "logName": "edge-18.0.log"
            }
        }
    }
}

问题在于desiredCapabilities 应该只是'capabilities'.我一直在到处寻找,试图找出创建的位置,以便我可以创建某种标志来切换它.

The issue is that desiredCapabilities should just be 'capabilities`. I have been looking everywhere trying to find out where is that created so that I can created some sort of flag to be able to switch it.

有什么想法吗?

推荐答案

Using Protractor 6.0 解决了我的问题,但破坏了我的所有测试.

Using Protractor 6.0 solve my issue, but broke all my tests.

通过修补 selenium-webdriver 包,我能够继续使用 5.4.1.看看 Protractor 6 的做法,我对 Protractor 5.4.1 做了:

I was able to keep using 5.4.1 by patching the selenium-webdriver package. Looking at the way Protractor 6 did it, I did it to Protractor 5.4.1:

我编辑了位于 node_modules/selenium-webdriver/lib/webdriver.js 的文件并添加了以下内容:

I edited the file located at node_modules/selenium-webdriver/lib/webdriver.js and added the following:

// Capability names that are defined in the W3C spec.
const W3C_CAPABILITY_NAMES = new Set([
    'acceptInsecureCerts',
    'browserName',
    'browserVersion',
    'platformName',
    'pageLoadStrategy',
    'proxy',
    'setWindowRect',
    'timeouts',
    'unhandledPromptBehavior',
]);

然后在同一个文件中修改 static createSession(executor, capabilities, opt_flow, opt_onQuit) 方法以添加以下内容:

Then in the same file I modify the static createSession(executor, capabilities, opt_flow, opt_onQuit) method to add the following:

    let W3CCaps = new Capabilities(capabilities);
    for (let k of W3CCaps.keys()) {
      // Any key containing a colon is a vendor-prefixed capability.
      if (!(W3C_CAPABILITY_NAMES.has(k) || k.indexOf(':') >= 0)) {
        W3CCaps.delete(k);
      }
    }

    cmd.setParameter('capabilities', W3CCaps);

在所有这些更改之后,到达 Selenoid 的请求是这样的:

After all those changes the request getting to Selenoid is like this:

{
    "desiredCapabilities": {
        "browserName": "MicrosoftEdge",
        "version": "18.0",
        "enableVNC": true,
        "enableVideo": false,
        "count": 1
    },
    "capabilities": {
        "browserName": "MicrosoftEdge"
    }
}

我的量角器 5 配置如下所示:

And my Protractor 5 config looks like this:

  multiCapabilities: [{
    browserName: 'MicrosoftEdge',
    version: '18.0',
    enableVNC: true,
    enableVideo: false
  }]

注意:

为了不用担心刷新安装或更新,我使用包 patch-package (https://github.com/ds300/patch-package) 创建一个补丁,当任何这些事件发生时应用该补丁.这是一个很棒的视频,解释了如何使用该软件包 https://www.youtube.com/watch?v=zBPcVGr6XPk

So that I don't have to worry about refresh installs or updates I use the package patch-package (https://github.com/ds300/patch-package) to create a patch that is applied when any of those events happen. Here is a great video explaining how to use that package https://www.youtube.com/watch?v=zBPcVGr6XPk

这篇关于量角器 W3C 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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