根据 this issue,ChromeDevTools 的网络节流功能在 ChromeDriver-2.26+ 中可用.如何在我们的 Protractor 配置文件中指定它?
基于四处搜索,我在配置文件中尝试了一些变化。我添加了一个 networkConnectionEnabled
属性(property)和prefs
阻止到 chromeOptions,如下所示。 (请注意,我没有同时执行它们。)
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'networkConnectionEnabled': {'type': 'GPRS'},
'chromeOptions': {
args: [
'--lang=en',
'--window-size=1280,1024'
],
prefs: {
'net.throttling_enabled': 'true,50,20'
}
}
}
],
我根据我的发现尝试的第二个选项 here (第 1983 行)。这些都不会改变 Protractor 运行的行为,当我手动测试并设置节流时,会在我的代码中触发某个条件。
编辑:还尝试添加如下内容 underchromeOptions: mobileEmulation:
{networkConnectionEnabled: true, networkThrottle: '2G'}
最佳答案
根据 changelog Selenium 3.4.0 中添加了用于在 Chrome 中操作网络模拟的 API。它们在 Protract 5.2.0 或更新版本中可用。
网络条件可以配置如下:
browser.driver.setNetworkConditions({
offline: false,
latency: 5, // Additional latency (ms).
download_throughput: 500 * 1024, // Maximal aggregated download throughput.
upload_throughput: 500 * 1024 // Maximal aggregated upload throughput.
});
这个代码应该放在
protractor.conf.js
内onPrepare
功能。
关于google-chrome - Protractor :在启用网络节流的情况下启动 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706831/