HTML5 中引入了 Application Cache,这意味着 Web 应用程序能够被缓存到本地,且可在没有网络的状况下也能访问该 Web 应用程序html
Application Cache 在如下3个方面具备明显优点html5
1.离线浏览:在没有网络状况下用户也可以使用 Web 应用程序android
2.速度快:缓存的资源被加载时速度很快浏览器
3.服务器负载小:浏览器只会从服务器更新有变化或新增的资源缓存
确认 Web 应用程序是否使用了改缓存特性的最简单方式就是直接查看网页 HTML 代码,若是其源码中具备以下包括 manifest 属性的标签则说明使用了 Application Cache 特性服务器
<! DOCTYPE HTML>网络
<html manifest="demo.appcache">app
...ui
</html>htm
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();
...