Handling local storage

UI.LocalStorage.get

Get the value of a property from local storage for the originopen in new window of the current page.

Returns null if the property does not exist.

If the property exists, its value will be automatically parsed as a JSON object if it is a valid JSON object, otherwise it will be returned as a string.

Usage

UI.LocalStorage.get(name)
ParameterTypeRemarks
namestringThe name of the property to get from local storage

Example(s)

Here's how we can access the local storage in our test script to get the value of the cart property for example:

var cart = UI.LocalStorage.get("cart")

UI.LocalStorage.set

Set a property in local storage for the originopen in new window of the current page.

If the property already exists in local storage, the value is overriden.

Usage

UI.LocalStorage.set(name, value)
ParameterTypeRemarks
namestringThe name of the property to put in local storage
valueanyThe value to the property to put in local storage. If the value is not a string, it will be stringified before saving.

Example(s)

Set the theme property in local storage to {"dark_mode": true}:

UI.LocalStorage.set("theme", {"dark_mode": true})

UI.LocalStorage.delete

Delete a property in local storage for the originopen in new window of the current page.

Usage

UI.LocalStorage.delete(name)
ParameterTypeRemarks
namestringThe name of the property to delete from local storage

Example(s)

Delete the cart property from local storage:

UI.LocalStorage.delete("cart")

UI.LocalStorage.deleteAll

Delete all properties in local storage for the originopen in new window of the current page.

Usage

UI.LocalStorage.deleteAll()
Last Updated: