仅在无头 chrome 中测试失败

我有一些使用 wdio 的集成测试,它们都通过了。但是,当我在无头 chrome 中运行它们时,这些测试之一失败了。我收到此错误:


1) Reset password by submitting a new password "before all" hook:


element ("#identifierNext") still not existing after 15000ms

问题出在这行代码中:


browser.waitForExist('#identifierNext');

这很奇怪,因为我waitForExist(<element id>)也在其他测试中使用了,它们甚至在无头 chrome 中也通过了。我还尝试将waitFor限制增加到 30000 毫秒,但无论如何还是失败了。


这是我的 wdio 配置:


exports.config = {

    specs: [

        './test/pageobjects/**/reset_password.spec.js'

    ],

    maxInstances: 1,

    capabilities: [{

        maxInstances: 1,

        browserName: 'chrome',

        'goog:chromeOptions': {

            args: ['--headless', '--disable-gpu', '--window-size=1280,800', '--no-sandbox', '--disable-dev-shm-usage']

        }

    }],

    sync: true,

    logLevel: 'silent',

    coloredLogs: true,

    deprecationWarnings: true,

    bail: 0,

    screenshotPath: './errorShots/',

    baseUrl: 'http://127.0.0.1:3000',

    waitforTimeout: 10000,

    connectionRetryTimeout: 90000,

    connectionRetryCount: 3,

    services: ['selenium-standalone'],

    framework: 'mocha',

    reporters: ['spec'],

    mochaOpts: {

        ui: 'bdd',

        timeout: 30000

    },

}

当我headless从 中删除时chromeOptions,此测试正常通过。任何想法为什么会发生这种情况?


守着一只汪
浏览 229回答 1
1回答

慕码人2483693

我发现了问题。Gmail 在不同浏览器中的显示方式不同。我browser.saveScreenshot('screenshot.jpg');在测试失败之前使用了屏幕截图,它显示页面看起来不同(使用我的本地语言而不是英语,并且具有不同的外观和按钮)。所以这就是测试找不到具有给定标识符的按钮的原因。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript