Time for action – accessing localStorage - Selenium

Imagine that your application has stored something in the localStorage while the user has been interacting with the application. An example of this might be if you were working in a word processing application and it auto saves what you have typed to the box every so often. If your application were offline, it can still save the information.

Let's see how we would access this.

  1. Create a new test class. You can use the example code at the beginning of the chapter to help you create it quicker.

  2. Accessing the LocalStorage object will require us to case the WebDriver object
    to it. This is similar to what we saw with BrowserConnection previously.

    LocalStoragestorageDriver = (LocalStorage) driver; storageDriver.size(); // returns 0 if there is nothing in there
  3. Now run your test class. It should look something like the following:

What just happened?

We have just seen how we can access LocalStorage, the Selenium WebDriver API, for accessing the browsers' localStorage object. This means that we can have a look and check what the application has stored on the user's local storage. If were to log

Session storage

Session storage is a very similar technology to local storage. The main difference is that it does not persist.If you were to close the tab and then reopen it, while using Firefox for example, session storage items will not be available where local storage will still be available.

Let's see how we can work with it.

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

Selenium Topics