Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium set Browser Chrome in OffLine mode

I am testing a Javascript application in Chrome browser. I want to load the page, and once loaded I would like to switch the browser to offline mode.

enter image description here

Note that I DON´T want to start the browser in offline mode as mentioned here: Selenium: How to set browser in offline mode?. Instead I want to start the browser connected and then switch it off and a specific moment.

Note that I don´t want to do it manually with the mouse, because this is for creating an automated test with Selenium. So I need to be able to send the instruction to go offline somehow with a script.

Is there anyway using Chrome to do that? could I modify the browser configuration executing a javascript? (probably not for security reasons but still wondering)

Thanks very much for your help.

like image 890
javigomez Avatar asked Nov 10 '16 15:11

javigomez


2 Answers

As was written in of. release notes:

ChromeDriver v2.26 (2016-12-09)

Resolved issue 984: Extend ChromeDriver capabilities to cover network throttling feature from Chrome DevTools [['OS-All', 'Pri-2']]

Here is full history log about this task. But there is no example, and no answer how it works.

like image 42
Alex.K Avatar answered Sep 21 '22 03:09

Alex.K


In Python, this can be achieved like this:

driver.set_network_conditions(offline=True, latency=5, throughput=500 * 1024)

PS: I am using ChromeDriver 2.32.

like image 72
Gabi Nagy Avatar answered Sep 20 '22 03:09

Gabi Nagy