接上回,贴UI部分的代码:
1.二层支持
#import "tuneup/tuneup.js"
var basic = {
config: {
shortTime: 1,
longTime: 5,
loadTime: 10,
},
init: function(){
this.wait(this.config.longTime);
var targetName=this.target().name();
var appName=this.target().frontMostApp().name();
var deviceModel=this.target().model();
var osVersion=this.target().systemVersion();
var osName=this.target().systemName();
var appVersion=this.target().frontMostApp().bundleID();
UIALogger.logStart("Autonavi-amap团队,UI驱动开始..." );
UIALogger.logMessage("调试包名称:" + appName);
UIALogger.logMessage("测试包版本:" + appVersion);
UIALogger.logMessage("设备名称:" + targetName);
UIALogger.logMessage("设备型号:" + deviceModel);
UIALogger.logMessage("系统版本:" + osVersion);
UIALogger.logMessage("操作系统类型:" + osName);
this.wait(this.config.shortTime);
},
body: function(){
return this.target().frontMostApp().mainWindow();
},
target: function(){
return UIATarget.localTarget();
},
say: function(words){
UIALogger.logMessage(words);
},
pass:function(){
UIALogger.logPass();
},
fail: function(){
UIALogger.logFail();
},
wait: function(seconds){
this.target().delay(seconds);
},
tap: function(ele){
var tapPointHorizontal =parseFloat(ele.rect().origin.x+(0.5*ele.rect().size.width));
var tapPointVertical =parseFloat(ele.rect().origin.y+(0.5*ele.rect().size.height));
this.target().tap({x:tapPointHorizontal,y:tapPointVertical});
this.wait(this.config.shortTime);
},
tree: function(){
this.target().logElementTree();
},
longTap: function(tmpX,tmpY){
this.target().tapWithOptions(
{ x: tmpX, y: tmpY },
{
duration: 2
}
);
this.wait(this.config.shortTime);
},
rollUp: function(){
this.target().dragFromToForDuration(
{ x: this.target().rect().size.width*0.5, y: this.target().rect().size.height*0.7 },
{ x: this.target().rect().size.width*0.5, y: this.target().rect().size.height*0.3 },
0.5
);
this.wait(this.config.shortTime);
},
rollDown: function(){
this.target().dragFromToForDuration(
{ x: this.target().rect().size.width*0.5, y: this.target().rect().size.height*0.3 },
{ x: this.target().rect().size.width*0.5, y: this.target().rect().size.height*0.7 },
0.5
);
this.wait(this.config.shortTime);
},rollLeft: function(){
this.target().dragFromToForDuration(
{ x: this.target().rect().size.width*0.7, y: this.target().rect().size.height*0.5 },
{ x: this.target().rect().size.width*0.3, y: this.target().rect().size.height*0.5 },
0.5
);
this.wait(this.config.shortTime);
},rollRight: function(){
this.target().dragFromToForDuration(
{ x: this.target().rect().size.width*0.3, y: this.target().rect().size.height*0.5 },
{ x: this.target().rect().size.width*0.7, y: this.target().rect().size.height*0.5 },
0.5
);
this.wait(this.config.shortTime);
},
}
2.一层特么的多,贴一条照着写把
#import "../basicAutomation.js"
var mainPage = {//主图页面
searchBar: function(){
return basic.body().images()[2];
},
voiceSearchButton: function(){
return basic.body().images()[2].images()[0];
},
locateButton: function(){
return basic.body().images()[8];
},
functionButton: function(){
return basic.body().buttons()[0];
},
roadStateButton: function(){
return basic.body().images()[4];
},
reportButton: function(){
return basic.body().buttons()[1];
},
enlargeButton: function(){
return basic.body().images()[6];
},
reduceButton: function(){
return basic.body().images()[12];
},
nearButton: function(){
return basic.body().buttons()["附近"];
},
routeButton: function(){
return basic.body().buttons()["路线"];
},
naviButton: function(){
return basic.body().buttons()["导航"];
},
moreButton: function(){
return basic.body().buttons()["更多"];
},
}
3.三层也复用不了,贴一条意思意思:
#import "../basicAutomation.js"
#import "../xPathVersion.js"
var main={//主图页面可用的方法
goNear: function(){
basic.tap(mainPage.nearButton());
},//前往附近页面
goRoute: function(){
basic.tap(mainPage.routeButton());
},//前往路线页面
goNavigation: function(){
basic.tap(mainPage.naviButton());
},//前往导航页面
goMore: function(){
basic.tap(mainPage.moreButton());
},//前往“更多”页面
search: function(key){
basic.tap(mainPage.searchBar());
mainSearchPage.searchField().setValue(key);
basic.tap(mainSearchPage.searchButton());
basic.wait(2);
},//主图一框搜某个关键词
changeCityTo: function(key){
basic.tap(mainPage.functionButton());
basic.tap(functionFloatPage.changeCityButton());
basic.tap(changeCityFloatPage.cityName(key));
basic.wait(1.5);
},//切换城市至某个城市(城市名称需要和程序内显示的吻合)
turnTo2d:function(){
basic.tap(mainPage.functionButton());
basic.tap(functionFloatPage.to2dButton());
basic.wait(0.3);
basic.tap(functionFloatPage.quitButton());
},//将地图切换至2d模式
turnTo3d:function(){
basic.tap(mainPage.functionButton());
basic.tap(functionFloatPage.to3dButton());
basic.wait(0.3);
basic.tap(functionFloatPage.quitButton());
},//将地图切换至2d模式
turnToSatellite:function(){
basic.tap(mainPage.functionButton());
basic.tap(functionFloatPage.toSatelliteButton());
basic.wait(0.3);
basic.tap(functionFloatPage.quitButton());
},//将地图切换至卫星模式
}
哎呦卧槽传不上来。。。。反正就是有一层代码全存底层UI,这层代码随版本实时更新。其他的所有代码都调用封装好的UI控件,这样就可以避免版本更新代码全变。
这边啥也传不上来,有人想要直接邮件我把guangyin.li@alibaba-inc.com