[Selenium] Android HTML5 中 Application Cache
2015-06-08 15:37
453 查看
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();
...
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();
...
相关文章推荐
- Android 控件之ProgressBar进度条
- pc android sqlcipher 加密
- android setContentView() 、LayoutInflater的区别
- Android中如何使用Cursor遍历Sqlite
- ListView的相关研究(一)
- Android raw to bmp
- [Selenium] Android HTML5 中 Web Storage
- Android OnMeasure
- android Path类
- [Android] 使用JSON和SharedPreferences存储用户自定义类
- android实习期日常笔记(一)
- at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:)
- [Android开发] Android应用与开发环境
- Mac OS-Android studio was unable to find a valid JVM解决办法
- [Selenium] Android 中旋转屏幕,触摸,滚动
- android 签名
- android 签名
- android 签名
- android设计模式
- android AsyncTask用法简单简绍