我是Appium的新手,在我的代码中,我已经提供了所需的功能并编写了一个工作正常的测试用例。现在我想用相同的代码启动另一个App进行第二次测试,我该怎么做? 我听说过startActivity(app-package,app Activity)但它不起作用,它表示没有为Web Driver定义startActivity()。
public class Calculator {
WebDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "14085521650378");
capabilities.setCapability("appPackage", "com.android.calculator2"); // This is package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator");
configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515/wd/hub"), capabilities);
}
@Test
public void testCal(){
driver.findElement(By.name("2")).click();
driver.findElement(By.name("+")).click();
driver.findElement(By.name("4")).click();
driver.findElement(By.name("=")).click();
}
@Test
public void Test2() { driver.startActivity("appPackage", "com.tttk.apc","appActivity","com.tttk.apc.DWDemoActivity");
for(int i=0; i<20;i++)
driver.findElement(By.className("android.widget.ImageButton")).click();
}
@AfterClass
public void teardown(){
//close the app
driver.quit();
}}
答案 0 :(得分:3)
似乎您正在尝试将该方法与WebDriver
实例一起使用。
startActivity
方法仅由StartsActivity
实施的接口AndroidDriver
提供。理想情况下这应该有效:
((AndroidDriver) driver).startActivity(<appPackage>, <appActivity>);
答案 1 :(得分:0)
public static void start() {
try {
((AndroidDriver) driver).startActivity("com.example.test", "com.example.LaunchApp");
} catch (Exception e) {
e.printStackTrace();
}
}
您必须输入应用程序包名称和活动名称才能使应用程序最大化。