appium自动化框架项目实战1——app初次使用引导页

本套框架实现了appium全自动执行,多台设备同时执行,自动启服务,自动生成testng文件,监听,重连.......只需写测试脚本

编写脚本顺序:page、action、test

本次实战以“联通手机营业厅app”为例进行脚本编写,一下的page类和action类可以合并,但分开更为明确,根据自己喜好来写;断言可写在action中也可以写在test中;

用例:app初次使用出现的引导页,滑动3次,可点击进入app应用

 appium自动化框架项目实战1——app初次使用引导页

 

1、创建配置文件

1)yindaopage1001.properties

ImageView=classname>android.widget.ImageView
ok_button=id>com.sinovatech.unicom.ui:id/custom_dialog_ok_button
tiaoguo_textview=id>com.sinovatech.unicom.ui:id/welcome_tiaoguo_textview
login=id>com.sinovatech.unicom.ui:id/home_login_button
2)android_caps.properties

app=C:/Users/jff/Desktop/mobileyy.apk
deviceName=devicename
automationName=Appium
newCommandTimeout=600
#appPackage=com.zhihu.android
#appActivity=com.zhihu.android.app.ui.activity.MainActivity
#appWaitActivity=com.hotyq.app.android.activity.MainActivity
appPackage=com.sinovatech.unicom.ui
appActivity=com.sinovatech.unicom.ui.WelcomeClient
noSign=true
unicodeKeyboard=true
resetKeyboard=true
deviceReadyTimeout=30
#noReset=true
#autoGrantPermissions=true
3)global.properties
 

androidserver=http://127.0.0.1
iosserver=http://127.0.0.1
senduser=vop_jiangfeifei@163.com
password=邮箱密码
tomail=1096101476@qq.com
implicitlyWait=10
input=
#0:android and ios;1:android;2:ios
deviceType=1
#appType 0:原生;1:混合;2:H5
appType=1
#0:均分测试用例每个设备;1:每个设备都执行所有用例
testType=1
#测试用例,“,”分割
testcases=com.crazy.appium.testcases.Test10010
2、创建page包,创建page类

package com.crazy.appium.page;
import com.crazy.appium.driver.CrazyMobileDriver;
import com.crazy.appium.utils.GetLocatorUtils;
import io.appium.java_client.MobileElement;
public class YinDaoPage10010{
public MobileElement start;
public MobileElement tiaoguo;
public CrazyMobileDriver driver;
public MobileElement ok_button;
public GetLocatorUtils locatorUtils;
public YinDaoPage10010(CrazyMobileDriver driver){
this.driver=driver;
this.locatorUtils=new GetLocatorUtils("configs/yindaopage10010.properties");
}
public MobileElement getStart() {
return driver.findElement(locatorUtils.getByLocalor("ImageView"));
}
public MobileElement getOk_button() {
return driver.findElement(locatorUtils.getByLocalor("ok_button"));
}
public MobileElement getTiaoguo() {
return driver.findElement(locatorUtils.getByLocalor("tiaoguo_textview"));
}
}
3、创建action包,Action类

package com.crazy.appium.action;
import static org.testng.Assert.assertEquals;
import org.testng.Assert;
import com.crazy.appium.driver.CrazyMobileDriver;
import com.crazy.appium.page.YinDaoPage10010;
public class YinDaoAction10010 extends YinDaoPage10010{
public YinDaoAction10010(CrazyMobileDriver driver) {
super(driver);
// TODO Auto-generated constructor stub
}
public void enterHomePage(){
//滑动
for(int i=0;i<3;i++){
driver.swipe("left", 500);
driver.sleep(1000);
}
//最后一页点击进入应用
getStart().click();
}
public void kaiqi(){
getOk_button().click();
driver.sleep(500);
//断言可以写在action中,方便维护,test中直接调用即可
Assert.assertEquals(driver.isElementExist(locatorUtils.getByLocalor("login")), true);
}
//直接跳过
public void skip(){
getTiaoguo().click();
}
}
4、创建test包,test类

1)TestBase

package com.crazy.appium.testcases;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import com.crazy.appium.driver.CrazyMobileDriver;

/**定义的driver对象,为driver、udid赋值
* 所写的Test都需要继承这个类,若需要一次执行多个测试类
* 1.配置如安卓,配好后;
* 2.配置global,testcase哪里用逗号分隔即可
* 3.找到main方法,执行
*/
public class TestBase {
CrazyMobileDriver driver;
//AppiumDriverLocalService service;
String udid;

public CrazyMobileDriver getDriver(){
return driver;
}
public String getUdid(){
return udid;
}
//类初始化
@Parameters({"udid","port"})
@BeforeClass
public void beforeClass(String udid,String port) throws Exception{
this.udid=udid;
driver=new CrazyMobileDriver("android",udid,port);
driver.implicitlyWaitDefault();
driver.sleep(10000);
}
@AfterClass
public void afterClass(){
driver.quit();
//service.stop();
}
}
2)测试用例,可以把断言写在action中,也可以写在test中

package com.crazy.appium.testcases;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.crazy.appium.action.YinDaoAction10010;
public class Test10010 extends TestBase{
@Test
public void tes001_yindao(){
YinDaoAction10010 yd=new YinDaoAction10010(driver);
yd.enterHomePage();
driver.sleep(1000);
//断言也可以写在test中
Assert.assertEquals(driver.getPageSource().contains("温馨提示"), true);
}
@Test(dependsOnMethods="tes001_yindao")
public void tes001_kaiqi(){
YinDaoAction10010 yd=new YinDaoAction10010(driver);
yd.kaiqi();
}

appium自动化框架项目实战1——app初次使用引导页

上一篇:android动态替换Fragment向下传递数据


下一篇:Appium的简答使用