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")); ...

Get Selenium Testing Tools Cookbook 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.