Site Loader
Auckland, New Zealand
In the last post we discussed how to automate android web apps using Appium, in this post we will discuss how to automate an android native app using Appium. For automating a mobile Native application, we need to first set the
  • Desired capability
  • Identify the control (elements of UI)
  • Write the code to perform operation
Here is the complete code for the above discussion.
public class FirstAppiumTest {

	// Create instance for Appium Driver
	AppiumDriver driver;

	@BeforeClass
	public void Setup() throws MalformedURLException {

		DesiredCapabilities cap = new DesiredCapabilities();
		cap.setCapability(MobileCapabilityType.DEVICE_NAME, "donatello");
		cap.setCapability(MobileCapabilityType.APP_PACKAGE,
				"com.example.calculator");
		cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "MainActivity");

		driver = new AndroidDriver(new URL(
				"http://127.0.0.1:4723/wd/hub"), cap);

	}

	@Test
	public void SimpleTest() {

		driver.findElementById("edtno1").SendKeys("20");

		driver.findElementById("edtno1").SendKeys("40");
		// Get the result 
		String result = driver.findElementById("txtResult").getText();

                if(result.equals("60"))
                   System.out.println("PASSED");
                else
                   System.out.println("FAILED");

	}
}

Here is the complete video of the above discussion. Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

One Reply to “Automating Native apps using Appium”

  1. Hello Karthik,

    I am trying to automate mobile application but I am unable to find element on emulator and unable to click on any element in myy physical device but in appium console result printing as click success,
    below is my code
    @Test
    public static void testhjg() throws MalformedURLException, InterruptedException {
    File classpathRoot = new File(System.getProperty(“user.dir”));
    File appDir = new File(classpathRoot, “APP”);
    File app = new File(appDir, “app-release (3).apk”);
    DesiredCapabilities capabilities =new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
    capabilities.setCapability(“deviceName”, “56123adf”);
    // capabilities.setCapability(“platformVersion”, “8.1.0”);
    capabilities.setCapability(“platformVersion”, “6.0.1”);
    capabilities.setCapability(“platformName”, “Android”);
    capabilities.setCapability(“autoGrantPermissions”, true);
    capabilities.setCapability(“app”, app.getAbsolutePath());
    capabilities.setCapability(“appPackage”, APPDetails.appPackage);
    capabilities.setCapability(“appActivity”, APPDetails.appActivity);
    // capabilities.setCapability(“app-wait-activity”, “com.parkquility.ui.authentication.AuthenticationActivity”);
    // capabilities.setCapability(“app-wait-activity”, “com.parkquility.ui.home.HomeActivity”);
    capabilities.setCapability(“app-wait-activity”, “com.parkquility.ui.Profile.ProfileActivity”);

    capabilities.setCapability(“newCommandTimeout”,”240″);

    driver= new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);//
    driver.findElementById(“googleButton”).click();
    driver.findElementById(“com.google.android.gms:id/account_name”).click();
    System.out.println(driver.getPageSource());

    WebElement ProfileTab = driver.findElementById(“payment_profile_button”);
    WebDriverWait wait = new WebDriverWait(driver, 2000);
    wait.until(ExpectedConditions.visibilityOf(ProfileTab));
    System.out.println(ProfileTab.getText());

    ProfileTab.click();

Leave a Reply

Your email address will not be published. Required fields are marked *