description |
---|
Learn how to use the different local storage commands to allow you to access properties in local storage for the origin of the current page in your UIlicious test. This document assumes you already have some knowledge about local storage. |
Get the value of a property from local storage for the origin 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.
UI.LocalStorage.get(name)
Parameter | Type | Remarks |
---|---|---|
name | string | The name of the property to get from local storage |
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")
Set a property in local storage for the origin of the current page.
If the property already exists in local storage, the value is overriden.
UI.LocalStorage.set(name, value)
Parameter | Type | Remarks |
---|---|---|
name | string | The name of the property to put in local storage |
value | any | The value to the property to put in local storage. If the value is not a string, it will be stringified before saving. |
Set the theme
property in local storage to {"dark_mode": true}
:
UI.LocalStorage.set("theme", {"dark_mode": true})
Delete a property in local storage for the origin of the current page.
UI.LocalStorage.delete(name)
Parameter | Type | Remarks |
---|---|---|
name | string | The name of the property to delete from local storage |
Delete the cart
property from local storage:
UI.LocalStorage.delete("cart")
Delete all properties in local storage for the origin of the current page.
UI.LocalStorage.deleteAll()