根据此问题,ChromeDevTools 的网络节流功能可在 ChromeDriver-2.26+ 中使用。如何在我们的量角器配置文件中指定它?
基于四处搜索,我在配置文件中尝试了一些变化。我已经向 chromeOptions添加了一个networkConnectionEnabled属性和一个prefs块,如下所示。(请注意,我没有同时执行它们。)
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'networkConnectionEnabled': {'type': 'GPRS'},
'chromeOptions': {
args: [
'--lang=en',
'--window-size=1280,1024'
],
prefs: {
'net.throttling_enabled': 'true,50,20'
}
}
}
],
Run Code Online (Sandbox Code Playgroud)
我根据我在此处找到的内容尝试的第二个选项(第 1983 行)。这些都不会改变量角器运行的行为,当我手动测试并设置节流时,会在我的代码中触发某个条件。
编辑:还尝试添加如下内容 underchromeOptions: mobileEmulation: {networkConnectionEnabled: true, networkThrottle: '2G'}