Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Google Chrome 38 introduced the new "Device Mode & Mobile Emulation" functionality in dev tools. 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:

enter image description here

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.

1 Answer

0 votes
by (62.9k points)

The API to control network emulation was added to ChromeDriver. And should be available for quite a while now. According to comments on the linked issue, you should use the 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 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

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing course online

Browse Categories

...