gpt4 book ai didi

java - Appium startActivity() 函数

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:13 25 4
gpt4 key购买 nike

我是 Appium 的新手,在我的代码中我提供了所需的功能并编写了一个运行良好的测试用例。现在我想用相同的代码启动另一个应用程序进行第二次测试,我该怎么做?我听说过 startActivity(app-package,app Activity) 但它不起作用,它说 startActivity() not defined for Web Driver 。

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();
}}

最佳答案

似乎您正在尝试将该方法与 WebDriver 实例一起使用。

startActivity 方法仅由AndroidDriver 实现的接口(interface)StartsActivity 提供。所以理想情况下这应该有效:

((AndroidDriver) driver).startActivity(<appPackage>, <appActivity>);

关于java - Appium startActivity() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37583945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com