使用 testcafe 在浏览器中设置用户代理

Setting user-agent in browsers with testcafe

我的 e2e UI 测试需要在浏览器中设置特定的用户代理。这在 Chrome 中不是问题,因为我可以像 'chrome:emulation:userAgent=...' 一样使用 Chrome 模拟,但我不能用 Firefox、Safari 等来实现。 有谁知道如何做到这一点?

很遗憾,此功能仅适用于 Chrome。

使用requestHooks修改header请求见下面link

https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/creating-a-custom-http-request-hook.html#the-onresponse-method