1、appium+testng+mysql
用例组装:xml-文件-方法-case集合/case;
F:\appium\AutoTestDemo-master\log
F:\appium\AutoTestDemo-master\target\allure-results
2、用例自动检查设计
自动化操作目的检查;
自动化操作后的埋点结果检查;
3、脚本执行检查的两种方法:
Assert.assertEquals(true,aftercount == beforecount+1|| aftercount == beforecount-1,
"wishlist_add"+" test fail,Not equals:");
/*categories_sort_pricefromlowtohigh_click排序点击*/
for(intj =0;j <2;j++) {
Thread.sleep(2000);
List sortItems = driver.findElementsByXPath("//android.widget.TextView[@text='Price: Low to High']");
if(sortItems.isEmpty()) {
j =0;
logger.info("wait2s");
}else{
logger.info("categories_sort_pricefromlowtohigh_click"+" test success!");
break;
}
}
4、小技巧
4.1、碰到返回结果不知道多久返回时,巧用for循环等待
//循环等待转圈圈消失
for(intj=0;j <2;j++) {
Thread.sleep(1000);
List sortItems = driver.findElementsByXPath("//android.widget.TextView[@text='Ship from Saudi']");
if(sortItems.isEmpty()) {
j =0;
}else{
break;
}
}
/*categories_sort_pricefromlowtohigh_click*/
flag = false;
for(int i=0 ; i<11 ; i++){
events.removeAll(events);
Event features_click = new Event();
features_click.setEventkey("categories_sort_pricefromlowtohigh_click");
features_click.setPagename("Categories");
events.add(features_click);
Map features_clickAllrs= BIQuery2.queryEvent(events,eventBefore);
Set features_clickGet = features_clickAllrs.keySet();
Assert.assertEquals(i<10,true,"###TestCase### "+"categories_sort_pricefromlowtohigh_click"+" Query bi fail");
for (Integer test:features_clickGet) {
if(test<0) {
Thread.sleep(10000);
logger.info("wait 10s");
break;
}else {
logger.info("###TestCase### "+features_clickAllrs.get(test).getEventkey()+" Query bi success!");
flag =true;
}
}
if(flag){
break;
}
}
4.2、巧用循环调整控件所在位置
intwidth = driver.manage().window().getSize().width;
intheight = driver.manage().window().getSize().height;
Thread.sleep(2000);
//当前屏幕轮询获取Recommended
for(inti =0;i <2;i++) {
Thread.sleep(1000);
List appiumItems = driver.findElementsByXPath("//android.widget.TextView[@text='Recommended']");
if(appiumItems.isEmpty()) {
driver.swipe(width /2,height *6/8,width/2,height /8,1000);
i =0;
}else{
i =3;
}
}
//轮询定位Recommended位于屏幕上方
for(inti =0;i <2;i++) {
WebElement recommendBtn =driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Recommended\")");
intstartY = recommendBtn.getLocation().y;
logger.info(" "+startY);
Thread.sleep(1000);
if(startY < height/12){
i=3;
}else{
driver.swipe(width /2,height *2/12,width/2,height /12,1000);
i=0;
}
}
4.3、调试报错日志有针对性的排查问题及打印日志
1、想调试打印class内所有的控件
//首次打开关闭freegift弹框
List textFieldsList = driver.findElementsByClassName("android.widget.ImageView");
for(inti=0;i
System.out.println(textFieldsList.get(i).getText());
//textFieldsList.get(i).click();
}