java 自动化测试用例_用java和junit编写app自动化测试用例
packagemyTest;import static org.junit.Assert.*;importio.appium.java_client.android.AndroidDriver;importorg.junit.After;importorg.junit.Before;importorg.junit.Test;importorg.openqa.selenium.By;importor
packagemyTest;import static org.junit.Assert.*;importio.appium.java_client.android.AndroidDriver;importorg.junit.After;importorg.junit.Before;importorg.junit.Test;importorg.openqa.selenium.By;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.remote.CapabilityType;importorg.openqa.selenium.remote.DesiredCapabilities;importjava.io.File;importjava.net.URL;importjava.util.List;importjava.util.concurrent.TimeUnit;public classMyTestCase {privateAndroidDriver driver;
@Beforepublic void setUp() throwsException {//设置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 = newDesiredCapabilities();
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);
}
@Afterpublic void tearDown() throwsException {
driver.quit();//driver.closeApp();//driver.launchApp();
}
@Testpublic voidtest_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!!!");
}
@Testpublic voidtest_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!!!");
}
}
更多推荐
所有评论(0)