Appium startActivity() Function

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

2 Answers

Seems like you are trying to use the method with a WebDriver instance.

The startActivity method is provided by an interface StartsActivity implemented by AndroidDriver only. So ideally this shall work :

((AndroidDriver) driver).startActivity(<appPackage>, <appActivity>);
0
public static void start() { try { ((AndroidDriver) driver).startActivity("com.example.test", "com.example.LaunchApp"); } catch (Exception e) { e.printStackTrace(); } }

You have to enter your app package name and activity name to maximize the app.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like