javascript - Selenium set Browser Chrome in OffLine mode - Stack Overflow

I am testing a Javascript application in Chrome browser. I want to load the page, and once loaded I wou

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.

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.

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.

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.

Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked Nov 10, 2016 at 15:55 javigomezjavigomez 1862 silver badges7 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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.

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.

In Java, you can use the following code to turn off the WiFi:

protected void disConnectInternet() throws IOException {
Map map = new HashMap();
map.put("offline", true);
map.put("latency", 5);
map.put("download_throughput", 500);
map.put("upload_throughput", 1024);


CommandExecutor executor = ((ChromeDriver)driver).getCommandExecutor();
Response response = executor.execute(
        new Command(((ChromeDriver)driver).getSessionId(), "setNetworkConditions", ImmutableMap.of("network_conditions", ImmutableMap.copyOf(map))));

}

You should be able to switch between online and offline mode using this:

browser.driver.setNetworkConnection(
  typeOrAirplaneMode: 0|1|2|3|4|5|6|7|boolean, wifi?: boolean, data?: boolean
);

More info here: http://webdriver.io/api/mobile/setNetworkConnection.html

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743782032a4505979.html

相关推荐

  • javascript - Selenium set Browser Chrome in OffLine mode - Stack Overflow

    I am testing a Javascript application in Chrome browser. I want to load the page, and once loaded I wou

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信