AppiumDemo
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AppiumDemo相关的知识,希望对你有一定的参考价值。
package appium;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.URL;
public class androidCalcTest {
private AppiumDriver driver;
@BeforeTest
public void setUp() throws Exception {
//初始化一些工作
//File classpathRoot = new File(System.getProperty("user.dir"));
//File appDir = new File(classpathRoot, "apps");
//File app = new File(appDir, "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", "Android");//使用哪种移动平台。ios, Android, orFirefoxOS?
capabilities.setCapability("deviceName","Android Emulator");//启动哪种设备,是真机还是模拟器
//capabilities.setCapability("deviceName","Galaxy S4");
capabilities.setCapability("platformVersion", "4.4");
//capabilities.setCapability("platformVersion", "4.3");
//capabilities.setCapability("app", app.getAbsolutePath());//应用的绝对路径,注意一定是绝对路径。如果指定了appPackage和appActivity的话,这个属性是可以不设置的。
capabilities.setCapability("appPackage", "com.android.calculator2");//待测试的app的package name
capabilities.setCapability("appActivity", ".Calculator");//待测试的app的Activity名字。原生app的话要在activity前加个"."
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void addNum() throws InterruptedException{
//Thread.sleep(10000);
driver.findElementByName("DELETE").click();
driver.findElementById("com.android.calculator2:id/digit1").click();//利用resource id定位。使用uiautomatorviewer查看
driver.findElementByName("+").click();//利用text定位
driver.findElementById("com.android.calculator2:id/digit2").click();
driver.findElementByName("=").click();
Thread.sleep(1000);
driver.findElementByName("CLR").click();
driver.findElementById("com.android.calculator2:id/digit3").click();
driver.findElementByName("").click();
driver.findElementById("com.android.calculator2:id/digit4").click();
driver.findElementByName("=").click();
Thread.sleep(1000);
driver.findElementByName("CLR").click();
driver.findElementById("com.android.calculator2:id/digit5").click();
driver.findElementById("com.android.calculator2:id/digit6").click();
driver.findElementById("com.android.calculator2:id/digit7").click();
driver.findElementByName("×").click();
driver.findElementById("com.android.calculator2:id/digit8").click();
driver.findElementById("com.android.calculator2:id/digit9").click();
driver.findElementById("com.android.calculator2:id/digit0").click();
driver.findElementByName("=").click();
Thread.sleep(2000);
driver.findElementByName("CLR").click();
driver.findElementById("com.android.calculator2:id/digit0").click();
driver.findElementById("com.android.calculator2:id/dot").click();
driver.findElementById("com.android.calculator2:id/digit0").click();
driver.findElementById("com.android.calculator2:id/digit1").click();
driver.findElementByName("÷").click();
driver.findElementById("com.android.calculator2:id/digit1").click();
driver.findElementById("com.android.calculator2:id/dot").click();
driver.findElementById("com.android.calculator2:id/digit5").click();
driver.findElementByName("=").click();
Thread.sleep(1000);
driver.findElementByName("CLR").click();
driver.findElementById("com.android.calculator2:id/digit1").click();
driver.findElementByName("÷").click();
driver.findElementById("com.android.calculator2:id/digit2").click();
driver.findElementByName("×").click();
driver.findElementById("com.android.calculator2:id/digit3").click();
driver.findElementByName("=").click();
Thread.sleep(1000);
driver.findElementByName("CLR").click();
}
}
以上是关于AppiumDemo的主要内容,如果未能解决你的问题,请参考以下文章