I want to interact with localStorage in browsers (Edge, Chrome) when testing by WDIO. For example, if I setItem into localStorage:
In CYPRESS:
window.localStorage.setItem(key, value)
In WDIO:
browser.setLocalStorage(key, value)
However, when I read document of WDIO, the command is deprecated and WDIO suggests using execute command instead.
I've tried using execute command browser.execute('window.localStorage.setItem(key, value)'), but it shows the error below:
Evaluation failed: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
at eval (eval at <anonymous> (:3:20), <anonymous>:1:8)
at pptr://__puppeteer_evaluation_script__:3:20
Error: Evaluation failed: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
at eval (eval at <anonymous> (:3:20), <anonymous>:1:8)
at pptr://__puppeteer_evaluation_script__:3:20
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Do you know how to fix it or Is there anyway to setItem into localStorage in WDIO?