Java appium startactivity() function

I am a novice of appium. In my code, I provide the required functions and write a well running test case. Now, I want to start another app with the same code for the second test. What should I do? I've heard of startactivity (APP package, APP activity), but it doesn't work. It says startactivity () that is 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();
}}

resolvent:

It seems that you are trying to use this method with a webdriver instance

The startactivity method is provided by the startsactivity interface implemented only by the androiddriver. Therefore, ideally, it will work:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>