O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Web storage – testing session storage

Similar to local storage, the 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 which 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:

@Test public void testHTML5SessionStorage() throws Exception { String clickcount=null; WebElement clickButton = driver.findElement(By.id("click")); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required