Time for action – setting the browser connection to offline or online - Selenium

In this section, we are going to turn the device's browser connectivity off. This means that we can check how the application works if it were offline. This is going to be a really useful feature as more and more applications try to take advantage of the move to mobile.

Let's see this in action.

  1. We are going to create a new test method in the class that we created in the previous section.

  2. In the test we are going to need to set the browser offline. We do this by casting to BrowserConnection and then using the method setOnline(). If we pass in true, it will set it online and if we set it to false, it will set the browser offline. Following is an example:
    ((BrowserConnection) driver).setOnline(false);

  3. When you have finished, your class should look like the following:

What just happened?

We have seen that we can simply turn the browser connection on and off on these devices and check that the browser is in the correct state, either online or offline, before moving on with the test.

Now,we will move on to how to access some of the HTML5 storage technologies.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics