Protractor: launch chrome with network throttling enabled

落爺英雄遲暮 提交于 2019-12-19 03:19:25

问题


The network throttling feature from Chrome DevTools is available in ChromeDriver-2.26+ according to this issue. How can I specify this in our protractor config file?

Based on searching around, I've tried variations of a couple things in the config file. I've added a networkConnectionEnabled property and a prefs block to chromeOptions, as below. (Note that I didn't do them both at the same time.)

multiCapabilities: [
    {
        'browserName': 'chrome',
        'platform': 'ANY',
        'networkConnectionEnabled': {'type': 'GPRS'},
        'chromeOptions': {
            args: [
                '--lang=en',
                '--window-size=1280,1024'
            ],
            prefs: {
                'net.throttling_enabled': 'true,50,20'
            }
        }
    }
],

The second option I tried based on what I found here (line 1983). None of these change the behavior of the protractor run, which when I manually test and set the throttling triggers a certain condition in my code.

Edit: also tried adding something like this underchromeOptions: mobileEmulation: {networkConnectionEnabled: true, networkThrottle: '2G'}


回答1:


According to changelog APIs for manipulating network emulation in Chrome were added in Selenium 3.4.0. And they are available in Protract 5.2.0 or newer.

Network conditions can be configured like below:

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.
});

This code should be placed in protractor.conf.js inside onPrepare function.



来源:https://stackoverflow.com/questions/44706831/protractor-launch-chrome-with-network-throttling-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!