I'm running a test using Selenium Webdriver (Java) and half way through the test I want to set my browser to offline, execute a couple of steps and turn the browser connection on again. Is there an easy way to do this, or maybe change the browser proxy to an non existent one (emulate offline) and set back to something valid again? I need to keep browser cache, browser local storage area and browser cookies between online, offline and online again.
Thanks
We can also move back in the browser with the help of a Javascript Executor in Selenium. It has the execute_script() method which allows Selenium to run Javascript commands. We have to execute the Javascript command window. history.go(-1) to go back to the previous page.
We can connect to an already open browser using Selenium webdriver. This can be done using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.
close() closes only the current window on which Selenium is running automated tests. The WebDriver session, however, remains active. On the other hand, the driver. quit() method closes all browser windows and ends the WebDriver session.
Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.
You may be able fake it by setting the WebDrivers PageLoadTimeout to zero.
In C# this worked for me:
driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0));
I'm Guessing in Java it would be something like this:
driver.manage().timeouts().pageLoadTimeout(0, TimeUnit.SECONDS);
After you're done doing that you could turn it back up to 30 seconds or something as some posts have indicated the default is.
Source for the pageLoadTimeout: https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html
And the default time: https://sqa.stackexchange.com/questions/2606/what-is-seleniums-default-timeout-for-page-loading
if u are using java and windows 7 then u can call cmd and pass release to turn off the network and using /renew to turn on the network. it works for me .
Process p = Runtime.getRuntime().exec("cmd /c ipconfig /release");
p = Runtime.getRuntime().exec("cmd /c ipconfig /renew");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With