问题描述
我是Appium的新手,在我的代码中,我提供了所需的所需功能,并编写了一个运行良好的测试用例.现在,我想用相同的代码启动另一个应用程序进行第二次测试,该怎么办?我听说过startActivity(app-package,app Activity),但是它没有用,它说未为Web Driver定义的startActivity().
I am new to Appium, In my code I have given required desired capabilities and wrote one test case that is working fine. Now I want to launch another App for second test in same code , how can I do that ?I heard about startActivity(app-package,app Activity) but its not working, it says 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
实例一起使用.
Seems like you are trying to use the method with a WebDriver
instance.
startActivity
方法仅由AndroidDriver
实现的接口StartsActivity
提供.因此,理想情况下,它将起作用:
The startActivity
method is provided by an interface StartsActivity
implemented by AndroidDriver
only. So ideally this shall work :
((AndroidDriver) driver).startActivity(<appPackage>, <appActivity>);
这篇关于Appium startActivity()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!