AndroidPageObjectTest_Chained.java
以下代码使用ApiDemos-debug.apk进行测试
//这个脚本用于演示PageFactory的功能:链式注解@AndroidFindBys、@IOSFindBys。具体用法参考页面类的代码。
package com.saucelabs.appium; import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.remote.MobileCapabilityType; import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit; import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory; import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenByAllPossible;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenChaided;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenSimple;
import com.saucelabs.appium.page_object.ios.TestAppScreenSimple; /**
* Please read about Page Object design pattern here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
* Please look at:
* {@link ApiDemosListViewScreenSimple}
* {@link ApiDemosListViewScreenChaided}
* {@link ApiDemosListViewScreenByAllPossible}
* {@link TestAppScreenSimple}
*
*/
public class AndroidPageObjectTest_Chained { private WebDriver driver;
private ApiDemosListViewScreenChaided apiDemosPageObject; @Before
public void setUp() throws Exception {
//File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File("E:/package");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); apiDemosPageObject = new ApiDemosListViewScreenChaided();
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS),
apiDemosPageObject);
} @After
public void tearDown() throws Exception {
driver.quit();
} /**
* Page Object best practice is to describe interactions with target
* elements by methods. These methods describe business logic of the page/screen.
* Here test interacts with lazy instantiated elements directly.
* It was done so just for obviousness
*/ @Test
public void androidChainSearchElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.chainElementViews.size());
} @Test
public void androidChainSearchElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.chainElementView.getAttribute("text"));
} @Test
public void androidOrIOSFindByElementsTest_ChainSearches(){
Assert.assertNotEquals(0, apiDemosPageObject.chainAndroidOrIOSUIAutomatorViews.size());
} @Test
public void androidOrIOSFindByElementTest_ChainSearches(){
Assert.assertNotEquals(null, apiDemosPageObject.chainAndroidOrIOSUIAutomatorView.getAttribute("text"));
} @Test
public void isAndroidElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.androidElementView.getAttribute("text"));
} @Test
public void areAndroidElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.androidElementViews.size());
}
}
页面类的代码如下:
package com.saucelabs.appium.page_object.android; import io.appium.java_client.android.AndroidElement; import java.util.List; import org.openqa.selenium.WebElement; import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AndroidFindBys;
import io.appium.java_client.pagefactory.iOSFindBy;
import io.appium.java_client.pagefactory.iOSFindBys; /**
*
* Here is the common sample shows how to use
* {@link AndroidFindBys} annotation to describe the chain of the
* searching for the target element of a native Android app content.
*
* It demonstrates how to declare screen elements using Appium
* page objects facilities.
*
* About Page Object design pattern read here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
*/
public class ApiDemosListViewScreenChaided { /**
* Page Object best practice is to describe interactions with target
* elements by methods. This methods describe business logic of the page/screen.
* Here lazy instantiated elements are public.
* It was done so just for obviousness
*/ @AndroidFindBys({//用多个定位方法描述一组元素。
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"), //the searching
//starts here
@AndroidFindBy(className = "android.widget.TextView") //this element is nested
//and so on
})
public List<WebElement> chainElementViews; @AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/content\")"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(id = "android:id/text1")
})
@iOSFindBys({@iOSFindBy(uiAutomator = ".elements()[0]"),
@iOSFindBy(xpath = "//someElement")})
public List<WebElement> chainAndroidOrIOSUIAutomatorViews; @AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
})
public WebElement chainElementView; @AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/content\")"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(id = "android:id/text1")
})
@iOSFindBys({@iOSFindBy(uiAutomator = ".elements()[0]"),
@iOSFindBy(xpath = "//someElement")})
public WebElement chainAndroidOrIOSUIAutomatorView; @AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/content\")"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(id = "android:id/text1")
})
public AndroidElement androidElementView; @AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/content\")"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(id = "android:id/text1")
})
public List<AndroidElement> androidElementViews;
}
AndroidPageObjectTest_Chained.java的更多相关文章
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题
背景起因: 记起以前的另一次也是关于内存的调优分享下 有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...
- Elasticsearch之java的基本操作一
摘要 接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...
- 论:开发者信仰之“天下IT是一家“(Java .NET篇)
比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- 死磕内存篇 --- JAVA进程和linux内存间的大小关系
运行个JAVA 用sleep去hold住 package org.hjb.test; public class TestOnly { public static void main(String[] ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- Java多线程基础学习(二)
9. 线程安全/共享变量——同步 当多个线程用到同一个变量时,在修改值时存在同时修改的可能性,而此时该变量只能被赋值一次.这就会导致出现“线程安全”问题,这个被多个线程共用的变量称之为“共享变量”. ...
- Java多线程基础学习(一)
1. 创建线程 1.1 通过构造函数:public Thread(Runnable target, String name){} 或:public Thread(Runnable target ...
随机推荐
- 解决npm 的 shasum check failed for错误
使用npm安装一些包失败,类似如下报错情况: C:\Program Files\nodejs>npm update npm npm ERR! Windows_NT 10.0.14393 np ...
- Reactjs 的 PropTypes 使用方法
propTypes 使用來規範元件Props的型別與必需狀態 var Test = React.createClass({ propTypes: { // required requiredFunc: ...
- 两种const函数
有两种const函数,声明如下:1.const T func();2.T func() const;第一种表示返回的是const的类型,也即返回的值不能作为左值,楼主懂的.第二种表示该成员函数不能修改 ...
- k8s-pod的生命周期
1.pod资源-spec.containers - name:镜像运行起来之后叫容器,该字段为容器名 image:镜像名字 imagePullPolicy:表示从哪拉取镜像, Always:不管本地有 ...
- 网络流24T 太空飞行计划问题
题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的 ...
- restful的认识和用法
目录 一.restful的认识 1.基本概念 2.规范和约束 3.使用标准的状态码 二.具体使用 1.简单概括 2.根据id查询一个员工 3.查询所有员工 4.保存一个员工 5.根据id修改员工 6. ...
- ie下li标签中span加float:right不换行问题解决方案
在IE6,IE7下使用标签时,在加入右浮动样式(float:right)后,会换行的bug解决方案:bug案例:新闻列表中,为使时间右对齐,加右浮动产生换行 <ul> <li> ...
- SilverLight:基础控件使用(6)-Slider控件
ylbtech-SilverLight-Basic-Control:基础控件使用(6)-Slider控件 Slider 控件 Slider 控件的 ValueChanged 事件 1.A,返回顶部 S ...
- 机器学习(十三)——机器学习中的矩阵方法(3)病态矩阵、协同过滤的ALS算法(1)
http://antkillerfarm.github.io/ 向量的范数(续) 范数可用符号∥x∥λ表示. 经常使用的有: ∥x∥1=|x1|+⋯+|xn| ∥x∥2=x21+⋯+x2n−−−−−− ...
- sql导入数据库
有问题可以尝试加上这句 DROP TABLE IF EXISTS `t_saler_login_log`;