Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bugdiver/taiko-storage
A taiko plugin to interact with browser storages
https://github.com/bugdiver/taiko-storage
chrome localstorage plugin sessionstorage taiko
Last synced: 4 months ago
JSON representation
A taiko plugin to interact with browser storages
- Host: GitHub
- URL: https://github.com/bugdiver/taiko-storage
- Owner: BugDiver
- License: mit
- Created: 2019-09-09T14:39:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T09:34:43.000Z (about 2 years ago)
- Last Synced: 2024-10-09T11:28:55.584Z (4 months ago)
- Topics: chrome, localstorage, plugin, sessionstorage, taiko
- Language: JavaScript
- Homepage:
- Size: 1.38 MB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
[![npm version](https://badge.fury.io/js/taiko-storage.svg)](https://badge.fury.io/js/taiko-storage)
[![Actions Status](https://github.com/bugdiver/taiko-storage/workflows/tests/badge.svg)](https://github.com/BugDiver/taiko-storage/actions)# taiko-storage
A taiko plugin to interact with browser storages (localStorage and sessionStorage).
## Installation
- `npm install taiko-storage --save`
## Usage
```javascript
const { openBrowser, closeBrowser, click, storage: { localStorage, sessionStorage} } = require('taiko');/*
ORconst { openBrowser, closeBrowser, click, storage } = require('taiko');
const {localStorage, sessionStorage} = storage;*/
(async () => {
try {
await openBrowser();
await localStorage.setItem("Key", "Value");
let value = await localStorage.getItem("Key");
// more actions
// ...
} finally {
await closeBrowser();
}
})();
```## APIs
The plugin exposes two variables `localStorage` and `sessionStorage` which represents to the respective storages.
The APIs for both the storage are same and try to very close the the native storage apis.### `setItem(key, value)`
set the given key value to storage
```js
await localStorage.setItem(key, value);
// or
await sessionStorage.setItem(key, value);```
### `getItem(key)`
featch the value for given key from storage
```js
await localStorage.getItem(key);
// or
await sessionStorage.getItem(key);```
### `hasItem(key)`
validate if the given key exists in storage.
```js
await localStorage.hasItem(key);
// or
await sessionStorage.hasItem(key);```
### `removeItem(key)`
remove the item with given key from the storage.
```js
await localStorage.removeItem(key);
// or
await sessionStorage.removeItem(key);```
### `clear()`
clear the stoarage
```js
await localStorage.clear();
// or
await sessionStorage.clear();```
### `length()`
tell the no of items in storage.
```js
await localStorage.length();
// or
await sessionStorage.length();```
## Passing Taiko options to APIS,
* The API's allows to pass a optional argument `options` which will be passed to taiko's `evaluate` API (used internally in storage APIs)
Example:
```js
await localStorage.setItem(key, value, { waitForNavigation: false });
```
## Use in Taiko REPL
To launch the REPL type `taiko --plugin taiko-storage` in your favorite terminal application. This will launch the Taiko Prompt.
e.g
`Version: 0.7.0 (Chromium:74.0.3723.0) Type .api for help and .exit to quit`You should now have full access to localStorage and sessionStorage apis in the taiko REPL window