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; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class HTML5SessionStorage...