Shiekha Gurung
Shiekha Gurung

Reputation: 31

How to turn off internet for desktop using selenium (java)?

I have a test to verify the url when network settings are turned off. How to turn off internet in selenium using java?

Upvotes: 2

Views: 1601

Answers (2)

Taylan Derinbay
Taylan Derinbay

Reputation: 148

You cannot do anything like that with selenium. Selenium is a browser automation tool. You can only do stuff, what you can in a website.

As far as I know also Java API cannot do that. Just run a bash script as @Adnan Isajbegovic suggest.

For mac:

String[] env = {"PATH=/bin:/usr/bin/"};
String script = "sudo ifconfig wlan0 down";
Process process = Runtime.getRuntime().exec(script, env);

Upvotes: 2

Adnan Isajbegovic
Adnan Isajbegovic

Reputation: 2297

With windows you can use cmd commands to turn off internet:

Runtime.getRuntime().exec("cmd /c ipconfig /release");

later, you bring it back with:

cmd /c ipconfig /renew

Upvotes: 3

Related Questions