量角器:在启用网络节流的情况下启动 chrome [英] Protractor: launch chrome with network throttling enabled

查看:63
本文介绍了量角器:在启用网络节流的情况下启动 chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 这个问题.如何在我们的量角器配置文件中指定它?

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?

基于四处搜索,我在配置文件中尝试了一些变化.我已经向 chromeOptions 添加了一个 networkConnectionEnabled 属性和一个 prefs 块,如下所示.(请注意,我没有同时做这两件事.)

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'
            }
        }
    }
],

我根据我的发现尝试了第二个选项 这里(1983年行).这些都不会改变量角器运行的行为,当我手动测试和设置节流时,会在我的代码中触发特定条件.

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.

也尝试添加类似 underchromeOptions: mobileEmulation: {networkConnectionEnabled: true, networkThrottle: '2G'}

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

推荐答案

根据changelog 在 Selenium 3.4.0 中添加了用于在 Chrome 中操作网络模拟的 API.它们在 Protract 5.2.0 或更高版本中可用.

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

这段代码应该放在onPrepare函数内的protractor.conf.js中.

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

这篇关于量角器:在启用网络节流的情况下启动 chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆