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")); WebElement clicksField = driver.findElement(By.id("clicks")); JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; //Get current value of sessionStorage.clickcount, should be null clickcount = (String) jsExecutor...