Appuim+Maven+Java+TestNG+Jenkins自动化集成部署
环境搭建参考:https://blog.****.net/daffordil/article/details/89416436
maven安装参考:https://blog.****.net/daffordil/article/details/89419252
接下来直接进行maven项目创建
打开eclispe--new--other
修改pom.xml文件,添加相应的所需jar包
<!--appium依赖 -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!--testng 依赖 -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
在src/test/java中新建一个testng类,(若没有testNG插件的,可自行百度下eclipse安装testNG插件)new-other-
效果如下:
测试类代码如下:
public class AppuimTest {
private AndroidDriver<AndroidElement> driver;
@Test
public void f() throws InterruptedException {
Thread.sleep(100);
// 找到相应元素
WebElement el = driver.findElement(By.name("Add Contact"));
el.click();// 模拟点击
// 找到eidit控件
List<AndroidElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
// 为第一个edit控件设置值
textFieldsList.get(0).sendKeys("Some Name");
Thread.sleep(100);
WebElement spin = driver.findElement(By.id("com.example.android.contactmanager:id/contactPhoneTypeSpinner"));
spin.click();
Thread.sleep(100);
WebElement t = driver.findElement(By.name("手机"));
t.click();
Thread.sleep(100);
// 为第三个edit控件设置值
textFieldsList.get(2).sendKeys("[email protected]");
Thread.sleep(500);
WebElement spin2 = driver.findElement(By.id("com.example.android.contactmanager:id/contactEmailTypeSpinner"));
spin2.click();
Thread.sleep(500);
WebElement tt = driver.findElement(By.name("其他"));
System.out.println();
tt.click();
Thread.sleep(100);
System.out.println("App is done!");
}
@BeforeTest
public void beforeTest() {
// 获取当前程序的路径
File classpathRoot = new File(System.getProperty("user.dir"));
// 获取apps文件
File appDir = new File(classpathRoot, "apps");
// 获取apk文件
File app = new File(appDir, "ContactManager.apk");
// 包装数据发送给appium-servier
DesiredCapabilities capabilities = new DesiredCapabilities();
// 启动的设备名称
capabilities.setCapability("deviceName", "127.0.0.1:62001");// 夜神模拟器名称
// 系统平台版本
capabilities.setCapability("platformVersion", "5.1");
// app的绝对路径
capabilities.setCapability("app", app.getAbsolutePath());
// app的包名
capabilities.setCapability("appPackage", "com.example.android.contactmanager");
// app的入口启动activity
capabilities.setCapability("appActivity", ".ContactManager");
// 连接appium启动相应app
try {
driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
System.out.println("App is launched!");//
}
@AfterTest
public void afterTest() {
// 关闭子窗口
driver.quit();
}
}
Run as --TestNG test运行,结果如下,
接下来部署Jenkins,若没有安装jenkins的,自行百度下jenkins安装,很简单的。
先启动jenkins
打开全局工具配置一下
配置如下:
点击保存!!!
然后点击先建任务:
点击底部的确定按钮
点击保存,
点击立即构建,前提appuim服务必须启动,并且连接了模拟器或真机
可查看运行时在控制台的输出日志
界面如下:
出现finished:SUCCSSS说明运行成功!!!
PS: