Selenium WebDriver 4

Assert localStorage state

Medium70 pts~25 min
  • localStorage
  • JavaScript execution
Practice app · Document Vault

File upload and download, cookies, localStorage, sessionStorage and JavaScript execution.

Test URL
/lab/selenium-assert-localstorage-state

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Read and change localStorage with JavaScript execution and verify the page reflects the new value.

Your task

  1. 1Click #save-local and assert #local-value reads “theme=dark”.
  2. 2Assert executeScript("return localStorage.getItem('theme')") returns “dark”.
  3. 3Set the value with executeScript("localStorage.setItem('theme', 'light')").
  4. 4Wait until #local-value reads “theme=light”.

Acceptance criteria

  • localStorage is read and written via executeScript
  • #local-value shows theme=light
  • At least 2 assertions pass

Selenium WebDriver 4 · Selenium · Files, windows & storage