Webdriverio: 在 W3C 模式下无法调用非 W3C 标准命令

创建于 2019-06-10  ·  3评论  ·  资料来源: webdriverio/webdriverio

环境(请填写以下信息):

  • WebdriverIO 版本: 4.14.4
  • 模式: WDIO 测试运行器
  • 如果是 WDIO Testrunner,运行同步/异步:同步
  • Node.js 版本: 10.15.0
  • NPM 版本: 6.4.1
  • 浏览器名称和版本: google-chrome-stable_75.0.3770.80-1
  • 平台名称和版本: LINUX
  • ** “wdio-cucumber-framework”:“^1.1.0”,“wdio-selenium-standalone-service”:“0.0.10”,

WebdriverIO的配置
如何配置 WebdriverIO 配置的示例

const path = require("path");

const isDebugMode = process.env.DEBUG === "true";

const chrome = 
    {
        browserName: "chrome",
        chromeOptions: {
            args: ["--window-size=1366,768"]
        }
    };

var capabilities = [chrome];

if(process.env.RUNNING_IN_DOCKER)
{
    capabilities = 
        [
            {
                browserName: "chrome",
                chromeOptions: {
                    args: ["--headless", "--window-size=1366,768"]
                }
            }
            // TO DO: Add headless Firefox see docker-compose.yml
        ];
} else if(process.env.ALL_BROWSERS)
{
    capabilities = 
        [
            chrome,
            {
                // set protected mode to the same value across all four zones in tools-> internet options -> security
                // also make sure zoom level is 100%
                browserName: "internet explorer"
            }
        ];
}

exports.config = {
    debug:  isDebugMode,
    execArgv: isDebugMode ? ['--inspect=9299'] : [],
    sync: true,
    maxInstances: 1,
    //maxInstances: isDebugMode ? 1 : 10,
    // Use selenium standalone server locally so we don't have a seperate selenium server in a seperate command prompt
    // Use the selenium grid via docker on TC
    services: process.env.RUNNING_IN_DOCKER ? [] : ["selenium-standalone"],
    seleniumLogs: "./logs",

    specs: [
        "./features/**/*.feature"
    ],

    exclude: [
        "./features/**/topic-page.feature"
    ],

    capabilities: capabilities,

    logLevel: "verbose",
    coloredLogs: true,
    screenshotPath: "./errorShots/",
    baseUrl: "https://*********/",
    reporters: process.env.RUNNING_IN_DOCKER ? ["spec", "teamcity"] : ["spec"],

    // Use BDD with Cucumber
    framework: "cucumber",
    cucumberOpts: {
        compiler: ["js:babel-register"], // Babel so we can use ES6 in tests
        require: [
            "./steps/given.js",
            "./steps/when.js",
            "./steps/then.js"
        ],
        tagExpression: "not @pending", // See https://docs.cucumber.io/tag-expressions/
        timeout: 30000
    },

    // Set up global asssertion libraries
    before: function before() {
        const chai = require("chai");
        global.expect = chai.expect;
        global.assert = chai.assert;
        global.should = chai.should();
    },
}

描述错误
自升级 Chrome 和 ChromeDriver 以来,我收到以下错误:

Error: Promise was rejected with the following reason: unknown command: Cannot call non W3C standard command while in W3C mode at elementIdDisplayed("e88a07f5-2ca3-42ad-b458-3d66797b37f0") - isVisible.js:71:55
如果您查看 ChromeDriver 75.0.3770.8 http://chromedriver.chromium.org/downloads的更改
你会看到它提到“最明显的变化是 ChromeDriver 现在默认运行在 W3C 标准兼容模式下。”

我已经设法通过在ChromeOptions中指定w3c: false来解决这个问题,但是我认为这不是正确的方法。 似乎有些地方在调用“非 w3c 标准”命令,我假设它在 webdriverio 中的某个地方。

重现
使用上述详细信息设置测试环境并运行 npm test。

预期行为
测试应该在没有错误Cannot call non W3C standard command while in W3C mode的情况下运行

最有用的评论

这不是 chrome 的问题,而是您如何指定选项的问题。 Chrome 75 默认符合 W3C,您必须将 W3C 设置为 false 才能使用 JSONWP(如发行说明中所述)

尝试提供类似的选项

'goog:chromeOptions': {
        'w3c': false,
        args: ["--headless", "--window-size=1366,768"]
    },

暂时关闭它,因为这是您如何定义选项的问题,而不是 WebdriverIO 的问题。

所有3条评论

这不是 chrome 的问题,而是您如何指定选项的问题。 Chrome 75 默认符合 W3C,您必须将 W3C 设置为 false 才能使用 JSONWP(如发行说明中所述)

尝试提供类似的选项

'goog:chromeOptions': {
        'w3c': false,
        args: ["--headless", "--window-size=1366,768"]
    },

暂时关闭它,因为这是您如何定义选项的问题,而不是 WebdriverIO 的问题。

@wswebcreation谢谢你是对的。 您能否将我指向发布说明,我似乎无法找到将 W3C 设置为 false 的位置。

谢谢

@wswebcreation如果我能点赞你的评论 100 次。

我来自 NightwatchJS,并且已经调查了这个错误 2 天。 我试图在 dockerized selenium hub 中运行 headless chromedriver。 将该片段添加到我的nightwatch.json文件中就可以了。 供其他人参考,我文件的该部分现在如下所示:

"chromeOptions": {
  "w3c": false,
  "args": [
    "--no-sandbox",
    "--headless",
    "--window-size=1920x1080"
  ]
}
此页面是否有帮助?
0 / 5 - 0 等级