Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate from protractor to set browser offline?

I have a scenario where it has to be tested when there is no connection. To automate this i thought making browser as offline and to test the scenario is feasible. Someone please help me how do we set browser offline during execution of a test from protractor? is there a way to access browser preferences from protractor ?

like image 231
Murali.Molluru Avatar asked Nov 18 '16 13:11

Murali.Molluru


Video Answer


1 Answers

Since I don't see what language you are coding in I'm gonna assume it's Java

this func turns 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))));

}
like image 136
Péter Szabó-tóth Avatar answered Oct 08 '22 12:10

Péter Szabó-tóth