微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Cypress 中运行测试时未反映 Set UserAgent (cypress.json)

如何解决在 Cypress 中运行测试时未反映 Set UserAgent (cypress.json)

我在 cypress.json 文件中设置了以下 userAgent,但是当我运行测试时...userAgent 更改没有反映出来,测试照常在 firefox/chrome 浏览器上运行。我在运行过程中没有看到任何与 userAgent 相关的浏览器更改......这意味着在设置用户代理之前和之后的测试运行没有区别。我的笔记本电脑详细信息:MacBook Pro(13 英寸,2017 款)

尝试的值:

手机/平板电脑:

Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0
Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0

桌面:

Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0

cypress.json

{
    "pluginsFile": "cypress/plugins/index.ts","supportFile": "cypress/support/index.ts","$schema": "https://on.cypress.io/cypress.schema.json","viewportWidth": 1440,"viewportHeight": 900,"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0","chromeWebSecurity": false,"defaultCommandTimeout": 10000,"screenshotsFolder": "./build/brazil-cypress-tests/screenshots","videosFolder": "./build/brazil-cypress-tests/videos","videoCompression": 32,"requestTimeout": 15000,"reporter": "mocha-multi-reporters","reporterOptions": {
        "configFile": "reporterConfig.json"
    },"retries": {
        "runMode": 1,"openMode": 1
    }
}

有人遇到过这个问题吗?我们如何在 cypress 测试中设置 userAgent 值?这阻碍了我针对不同平台的自动化。

附加信息: 还尝试通过 cli/script 设置 userAgent,但没有成功。

  "cy:sample-script": "cypress open --config userAgent=\"Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0\""

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。