Time for action – seeing if the browser is online - Selenium

In this section, we will have a look at seeing if the browser is online or offline. Currently, this only works on mobile drivers from Selenium WebDriver. In this section, we will need to cast the Selenium WebDriver object to BrowserConnection and then access the methods that are found on that object.

Let's get into action:

  1. Create a new test class using the example code at the beginning of the chapter.
    We can call the class TestBrowserConnection.

  2. Create a test method and add the following to it:

    assertTrue(((BrowserConnection) driver).isOnline());
  3. Your class should look like the following and when you run the test method it will pass:

What just happened?

We have seen that by casting the webdriver object to BrowserConnection, we have access to a number of new methods. These methods allow us to see if the browser is currently online or offline. They also allow us to set the browser to online or offline, which will be the next section of this book.

Setting the browser offline or online

Now that we know how to see if the browser is online or offline, let us have a look at setting the browser connection to online or offline. This is not part of HTML5 technologies, but will allow us to use the previous online call, which is part of HTML 5, and to check if our application cache has downloaded the relevant files.
Let's see this in action.

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

Selenium Topics