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自动化测试用例
原文地址:https://www.cnblogs.com/mgzc-1508873480/p/8280540.html
时间: 2024-10-10 19:10:14