ExecuteAutomation

Locating elements in Appium (Part b)

In the last post we discussed locating element using ID and in this post we will start to locate element of Android application using Here is the complete code for identifying control using different locators.
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.android.calculator2");
		cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "Calculator");
		// cap.setCapability("avd", "Test");

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

	}

	@Test
	public void SimpleTest() {

		// Click 5
		driver.findElementById("digit5").click();
		// Click 5
		driver.findElementById("digit6").click();
		// Click 5
		driver.findElementByAccessibilityId("plus").click();
		// Click 5
		driver.findElementById("digit9").click();
		// Click 5
		driver.findElementById("digit3").click();

		driver.findElementByAccessibilityId("equals").click();

		// Verify the result
		String result = driver
				.findElementByClassName("android.widget.EditText").getText();

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

	}
}

As you can see from the above code, we have also used the getText() method to get the text out from a control and verified if the text is as expected. Here is the complete video for 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