Time for action – accessing sessionStorage - Selenium

Imagine again that you are working against a word processing application but instead of it auto saving the text that you type to somewhere that is persisted, you only save it briefly waiting for the user to click save.

Let us see how we can use it.

  1. Let's just add a new testMethod to the class we created in the previous section. We can call it test Should Access Session Storage() .

  2. We will need to cast the WebDriver object to a SessionStorage object, so we can start accessing the methods it has available like the following:

    SessionStorage storage = (SessionStorage) driver; assertEquals(0, storage.size());
  3. Let's create our test and run it. It should look like the following:

What just happened?

We have just seen that the SessionStorage object acts a lot like the localStorage object that we worked with in the previous section of the chapter. We were able to get the SessionStorage methods by casting the Selenium WebDriver object. This gives us access to methods that map over to the JavaScript API available in the browser.


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

Selenium Topics