android 自动化

/ 测试开发 / 0 条评论 / 991浏览
uiautomator ant编译引用的lib
https://yq.aliyun.com/articles/59864
 <property name="jar.libs.dir" value="libs" />
 <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />

<classpath >
<fileset dir="${jar.libs.dir}" includes="*.jar" />
</classpath>

========================================================
android测试原理 http://wiki.eoeandroid.com/Testing_Fundamentals

instrument http://blog.csdn.net/startfromweb/article/details/7877361
android屏幕有关知识":
 像素密度,也就是PPI(pixels per inch)
http://colachan.com/post/3435
 像素密度在120左右的屏幕归为ldpi,160左右的归为mdpi
 iOS的尺寸单位为pt,Android的尺寸单位为dp:  1pt=1dp=1px(mdpi、iPhone 3gs)
  • ldpi [0.75倍]
  • mdpi [1倍]
  • hdpi [1.5倍]
  • xhdpi [2倍]
  • xxhdpi [3倍]
  • xxxhdpi [4倍]
//TextView[contains(@text, "")]
//TextView[@text='']
命令行安装appium:
https://cnodejs.org/topic/4f9904f9407edba21468f31e
http://testerhome.com/topics/657
nodejs + appium
http://blog.csdn.net/jlminghui/article/details/41121479
http://testerhome.com/topics/645

http://wenku.baidu.com/link?url=gefV5UyCig7F5ggbeciS9yS6jQM8YqkqgLz13iSbWXeCiBtIK7x2e7T-czHhkqzaPV_b79WbTS0WtVqkY53xMsx76HKW7_z9Ppd9kHrB5WG
appium用法
http://www.2cto.com/kf/201410/340345.html
appium版本包
http://pan.baidu.com/s/1jGvAISu#dirpath=%252FAppium%25E5%2590%2584%25E7%2589%2588%25E6%259C%25AC%25E5%25AE%2589%25E8%25A3%2585%25E5%258C%2585
https://bitbucket.org/appium/appium.app/downloads/
appium capabilities
http://www.easonhan.info/appium/2014/06/28/appium-07/

http://appium.io/slate/en/v1.3.4/#
// java
JavascriptExecutor js = (JavascriptExecutor) driver;HashMap<String, String> scrollObject = new HashMap<String, String>();scrollObject.put("direction", "down");scrollObject.put("element", ((RemoteWebElement) element).getId());js.executeScript("mobile: scroll", scrollObject);
// java
// slider values can be string representations of numbers between 0 and 1// e.g., "0.1" is 10%, "1.0" is 100%WebElement slider = driver.findElement(By.xpath("//window[1]/slider[1]"));slider.sendKeys("0.1");
// java
driver.sendKeyEvent(AndroidKeyCode.HOME);
// java
driver.currentActivity();
// java
driver.swipe(75, 500, 75, 0, 0.8)
// java
driver.pinch(element);
// java
driver.zoom(element);
// java
WebElement element = driver.findElement(By.name("Element Name"));HashMap<String, String> arguments = new HashMap<String, String>();arguments.put("element", element.getId());(JavascriptExecutor)driver.executeScript("mobile: scrollTo", arguments);
java-client github:
https://github.com/appium/java-client
操作集锦http://testerhome.com/topics/1809
如何获取android app的activity
http://www.58os.com/BBS/TechBSS/Article-26751.html
appium inspector
http://blog.sina.com.cn/s/blog_68f262210102v536.html

appium0.18.x-> 1.0改动
http://blog.csdn.net/zhubaitian/article/details/39753945

错误:com.android.uiautomator.core.Configurator
appium1.2.4+java-client2.1.jar可以(1.3.4出现这个问题)
https://github.com/appium/appium/issues/4296
adt版本问题:

http://pan.baidu.com/s/1c0rLAQO
appium有道云笔记
http://note.youdao.com/share/?id=4e03d92f63d5bcd3af9a702b2b307c83&type=note
UiObject中getChildCount和getChild方法解惑
http://www.tuicool.com/articles/32ARBz
uidevice longclick
http://stackoverflow.com/questions/16061478/android-uiautomator-long-click-on-device

instance or index
instance方法会将界面上所有相同类型的控件按顺序取出来,放到一个集合里(暂且这么理解吧,不知道放哪里了,囧),然后按照控件在集合的角标把想要的控件取出来;而index则是通过该控件所在层级的节点角标将对应的控件取出来。
http://www.shaoqun.com/a/107513.aspx
//验证信息未读-已读状态
UiObject uc = new UiObject(new UiSelector().resourceId("com.nq.mdm:id/listView_msg_list"));
UiObject superparent = uc.getChild(new UiSelector().className("android.widget.RelativeLayout").index(1));
UiObject superparent2 = uc.getChild(new UiSelector().className("android.widget.RelativeLayout").index(2));
UiObject parent = new UiObject(superparent.getSelector().childSelector(new UiSelector().resourceId("com.nq.mdm:id/layout_msg")).childSelector(new UiSelector().resourceId("com.nq.mdm:id/layout_1")));
UiObject parent2 = new UiObject(superparent2.getSelector().childSelector(new UiSelector().resourceId("com.nq.mdm:id/layout_msg")).childSelector(new UiSelector().resourceId("com.nq.mdm:id/layout_1")));
UiObject image = new UiObject(new UiSelector().resourceId("com.nq.mdm:id/imageView_read"));
//验证未读
if(!new UiObject(parent.getSelector().childSelector(image.getSelector())).exists()){
System.out.println("11111");
fileHelper.writeDataToFile(txtFile, "FAILED");
}
UiObject image2 = new UiObject(parent2.getSelector().childSelector(image.getSelector()));
//验证未读
if(!image2.exists()){
System.out.println("22222");
fileHelper.writeDataToFile(txtFile, "FAILED");
}
//点开未读 - 验证已读
parent2.clickAndWaitForNewWindow();
getUiDevice().pressBack();
if(image2.exists()){
System.out.println("33333");
fileHelper.writeDataToFile(txtFile, "FAILED");
}
//时间戳比较
for(int k=0;k<uc.getChildCount()-3;k++){
String text = uc.getChild(new UiSelector().resourceId("com.nq.mdm:id/textView_date").instance(k)).getText();
String text2 = uc.getChild(new UiSelector().resourceId("com.nq.mdm:id/textView_date").instance(k+1)).getText();
if(text2.compareTo(text)>0){
fileHelper.writeDataToFile(txtFile, "FAILED");
break;
}
}
根据text查同级别layout
UiObject policy_text = new UiObject(new UiSelector().text(policyName));
//删除
policy_text.getFromParent(new UiSelector().resourceId("com.nq.mdm:id/layout_del")).click();