[Selenium] Android HTML5 中 Application Cache

HTML5 中引入了 Application Cache,这意味着 Web 应用程序可以被缓存到本地,且可在没有网络的情况下也能访问该 Web 应用程序

Application Cache 在以下3个方面具有明显优势

1.离线浏览:在没有网络情况下用户也可使用 Web 应用程序

2.速度快:缓存的资源被加载时速度很快

3.服务器负载小:浏览器只会从服务器更新有变化或新增的资源

确认 Web 应用程序是否使用了改缓存特性的最简单方式就是直接查看网页 HTML 代码,如果其源码中具有如下包括 manifest  属性的标签则说明使用了 Application Cache 特性

<! DOCTYPE HTML>

<html manifest="demo.appcache">

...

</html>

Selenium WebDriver 具有一个名为 AppCacheStatus 的枚举量,用于标记当前 Application Cache的状态,包括 0(UNCACHED)、1(IDLE)、2(CHECKING)、3(DOWNLOADING)、4(UPDATEREADY)、5(OBSOLETE)

下面以获取当前 Web 应用程序的缓存状态为例 展示对 Application Cache 的接口如何使用

package com.learingselenium.android;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import org.openqa.selenium.WebDrivver;

import org.openqa.selenium.android.AndroidDriver;

import org.openqa.selenium.html5.AppCacheStatus;

import org.openqa.selenium.html5.ApplicationCache;

...

WebDriver driver = new AndroidDriver("http://localhost:8888/wd/hub");

driver.get("http://w3school.com/html/tryhtml5_html_manifest.htm");

AppCacheStatus status = ((ApplicationCache) driver).getStatus();

assertEquals(status, AppcacheStatus.DOWNLOADING);

System.out.println("Application Cache's status is : " + status.toString());

driver.quit();

...

原文地址:https://www.cnblogs.com/feifeidxl/p/4561088.html