使用铬和硒进行网络节流 [英] Network throttling with chrome and selenium

查看:160
本文介绍了使用铬和硒进行网络节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Chrome 38推出了新的,但问题是具体关于铬+硒。

解决方案

控制网络仿真的API 已添加到ChromeDriver。现在应该可以使用一段时间了。根据评论的链接问题,您应该使用版本至少2.26因为一些错误修正。



根据Selenium changelog 绑定可用于以下语言:

>

如果您需要以其他语言进行这些绑定,您应该打开与上述类似的问题/贡献实现。



Python的示例用法是如下:

  driver.set_network_conditions(
offline = False,
latency = 5,#additional latency( ms)
download_throughput = 500 * 1024,#最大吞吐量
upload_throughput = 500 * 1024)#最大吞吐量


Google Chrome 38 introduced the new "Device Mode & Mobile Emulation" functionality in devtools. In addition to choosing a device for emulation, it is also possible to emulate different network conditions:

Optimizing your site's performance under varying network conditions is a key aspect of developing for a mobile audience.

Device mode's network conditioning allows you to test your site on a variety of network connections, including Edge, 3G, and even offline. Select a connection from the preset dropdown to apply network throttling and latency manipulation.

For example, we can set it to be like in good old days - GPRS 50 Kbps:

Now we have a good use case for it - we have an internal application for network speed testing. And this new emulation functionality is very helpful for manual testing. But, we'd like to automate it.

Question is:

Is it possible to start chrome via selenium with specified network conditions? Is it something that can be controlled through chrome preferences or command-line arguments?


There are certainly multiple options to simulate slow internet connection, but the question is specifically about chrome+selenium.

解决方案

The API to control network emulation were added to ChromeDriver. And should be available for quite a while now. According to comment in the linked issue you should use version at least 2.26 because of some bugfix.

According to Selenium changelog bindings are available for these languages:

  • JavaScript as of version 3.4.0 (commit)
  • Python as of version 3.5.0 (commit)
  • Ruby as of version 3.11.0 (commit)

If you need these binding in other languages you should probably open issue/contribute implementation similar to one of the above.

Example usage from Python is below:

driver.set_network_conditions(
    offline=False,
    latency=5,  # additional latency (ms)
    download_throughput=500 * 1024,  # maximal throughput
    upload_throughput=500 * 1024)  # maximal throughput

这篇关于使用铬和硒进行网络节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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