Code Monkey home page Code Monkey logo

taiko-storage's Introduction

Taiko Storage

npm version Actions Status

taiko-storage

A taiko plugin to interact with browser storages (localStorage and sessionStorage).

Installation

  • npm install taiko-storage --save

Usage

const { openBrowser, closeBrowser, click, storage: { localStorage, sessionStorage} } = require('taiko');

/*
OR

const { 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

await localStorage.setItem(key, value);
// or
await sessionStorage.setItem(key, value);

getItem(key)

featch the value for given key from storage

await localStorage.getItem(key);
// or
await sessionStorage.getItem(key);

hasItem(key)

validate if the given key exists in storage.

await localStorage.hasItem(key);
// or
await sessionStorage.hasItem(key);

removeItem(key)

remove the item with given key from the storage.

await localStorage.removeItem(key);
// or
await sessionStorage.removeItem(key);

clear()

clear the stoarage

await localStorage.clear();
// or
await sessionStorage.clear();

length()

tell the no of items in storage.

await localStorage.length();
// or
await sessionStorage.length();

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.