【用java和junit编写app自动化测试用例】历览千载书,时时见遗烈。这篇文章主要讲述用java和junit编写app自动化测试用例相关的知识,希望能为你提供帮助。
用java和junit编写app自动化测试用例
package myTest; import static org.junit.Assert.*; import io.appium.java_client.android.AndroidDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.net.URL; import java.util.List; import java.util.concurrent.TimeUnit; public class MyTestCase { private AndroidDriver driver; @Before public void setUp() throws Exception { //设置apk的路径 File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "apps"); File app = new File(appDir, "calculator_debug_2.3.1_10000_svn80220_200_staging_2017_12_16.apk"); //设置自动化相关参数 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName", "7N2SSE158P001892"); capabilities.setCapability("deviceName", "P4M7N15104001008"); //设置安卓系统版本 capabilities.setCapability("platformVersion", "4.4.2"); capabilities.setCapability("platformVersion", "6.0"); //设置apk路径 capabilities.setCapability("app", app.getAbsolutePath()); //设置app的主包名和主类名 capabilities.setCapability("appPackage", "com.gomo.calculator"); capabilities.setCapability("appActivity", ".ui.activity.MainActivity"); //初始化 driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }@After public void tearDown() throws Exception { driver.quit(); //driver.closeApp(); //driver.launchApp(); }@Test public void test_Add() { driver.findElement(By.id("com.gomo.calculator:id/input_num_1")).click(); driver.findElement(By.id("com.gomo.calculator:id/display_op_add")).click(); driver.findElement(By.id("com.gomo.calculator:id/input_num_2")).click(); driver.findElement(By.id("com.gomo.calculator:id/display_eq")).click(); System.out.println("test_Add success!!!"); }@Test public void test_Mul() { driver.findElement(By.id("com.gomo.calculator:id/input_num_3")).click(); driver.findElement(By.id("com.gomo.calculator:id/op_mul")).click(); driver.findElement(By.id("com.gomo.calculator:id/input_num_4")).click(); driver.findElement(By.id("com.gomo.calculator:id/display_eq")).click(); System.out.println("test_Mul success!!!"); }}
python版请移步:用python和unittest编写app自动化测试用例
推荐阅读
- Android中图形截取的方式介绍
- flask 中xx.init_app(app)方法
- bean工厂和ApplicationContext
- 乐视超级电视s40 air价格多少钱?乐视电视s40 air价格
- 乐视超级电视s50 air价格多少钱?乐视s50 air超级电视价格
- ipad air2设置怎样?ipad air2设置参数
- ipad air2尺寸多大?ipad air2屏幕尺寸大小
- 天猫魔筒是啥?天猫魔筒技巧设置
- 天猫魔筒申请成功后啥时候发货?天猫魔筒申请成功后发货时间