Android HTML5 in Web Storage

Source: Internet
Author: User

In HTML5, the new feature of Web Storage allows users to store data in a local browser. Cookies can be used to accomplish this task in earlier browsers, but web Storage are more secure and efficient, and web Storage are stored by key-value pairs, and only their Web applications can access stored data

The Web Storage is divided into the following 2 types

1. Localstorage: Stored data does not expire permanently

2. Sessionstorage: Stored data is only valid in the current session

Localstorage and Sessionstorage information can be viewed in the Resources tab of Chrome's developer tools

Example of Operation Localstorage:

Package com.learingselenium.android;

Import static org.junit.Assert.assertEquals;

Import org.junit.*;

Import Org.openqa.selenium.WebDriver;

Import Org.openqa.selenium.html5.LocalStorage;

Import Org.openqa.selenium.html5.WebStorage;

Import Org.openqa.selenium.android.AndroidDriver;

...

Webdriver Driver = new Androiddriver ("Http://localhost:8888/wd/hub");

Driver.get ("http://www.1.com");

Localstorage localstorage = ((webstorage) driver). Getlocalstorage ();

System.out.println ("The size of Localstorage is:" + localstorage.size ());

Localstorage.setitem ("Key1", "Learningselenium");

System.out.println (Localstorage.getitem ("Key1"));

Driver.quit ();

...

From the execution results, Localstorage retains the previously stored data. If you need to ensure that localstorage is clean every time you run a test case, you need to execute the following code snippet before using Localstorage:

Localstorage localstorage = ((webstorage) driver). Getlocalstorage ();

Localstorage.clear ();

Example of Operation Sessionstorage:

...

Webdriver Driver = new Androiddriver ("Http://localhost:8888/wd/hub");

Driver.get ("http://www.1.com");

Sessionstorage sessionstorage = ((webstorage) driver). Getsessionstorage ();

System.out.println ("The size of Sessionstorage is:" + sessionstorage. Size ());

Sessionstorage. SetItem ("Key1", "Learningselenium");

System.out.println (Sessionstorage getItem ("Key1"));

Driver.quit ();

...

From the execution results, Sessionstorage does not retain the data stored in the previous session, that is, the data stored in Sessionstorage is only valid in the current session.

Android HTML5 in Web Storage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.