Web storage – testing session storage

Similar to local storage, session storage stores the data for only one session. The data is deleted when the user closes the browser window. We can access the session storage using the sessionStorage interface through JavaScript.

In this recipe, we will verify that a web page stores data in session storage as expected.

How to do it...

Let's create a test case that will load a web page that implements a counter and stores the value of the counter every time a button is clicked in session storage. We will verify that a new counter value is stored in session storage:

package com.secookbook.examples.chapter10; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.JavascriptExecutor; ...

Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.