Device Web Automation using Android WebDriver

Step by step instructions:

  1. Install and Setup Android SDK/ADT
  2. Download “android-server-2.21.0.apk” from https://code.google.com/p/selenium/downloads/detail?name=android-server-2.21.0.apk to Android SDK “platform-tools” folder. (Note that the latest version “android-server-2.32.0.apk” might throw an exception “org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.”)
  3. Launch android emulator through Android Virtual Device Manager in Eclipse toolbar and unlock the device
  4. Execute the following commands based on your location of platform-tools folder

cd C:\Users\saikatd\Appium\adt-bundle-windows-x86_64-20131030\sdk\platform-tools

adb devices
adb -s emulator-5554 -e install -r android-server-2.21.0.apk
adb -s emulator-5554 shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
adb -s emulator-5554 forward tcp:8080 tcp:8080

  1. Once the WebDriver screen launches in device emulator, run the following program as Java Application using Eclipse
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.AndroidDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class DeviceAutomation {

       /**
       * @param args
       */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
              try {
                     WebDriver driver = new AndroidDriver();
                     driver.get("http://www.amazon.com/gp/aw/d/B00AWH595M");
                     driver.findElement(By.id("dpSearchKeyword")).click();
                     driver.findElement(By.id("dpSearchKeyword")).clear();
                     driver.findElement(By.id("dpSearchKeyword")).sendKeys("prime membership");
                     driver.findElement(By.xpath("//*[contains(@class,'a-button-text')][normalize-space(text())='Go']")).click();
                     Thread.sleep(5000);
                     //Validate the price of prime subscription
                     driver.get("http://www.amazon.com/gp/aw/d/B00EW0FYA0/");
                     WebDriverWait wait = new WebDriverWait(driver,30);
                     wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[contains(@class,'a-color-price a-size-medium')][normalize-space(text())='$99.00']")));
                     System.out.println("Test Case Passed!!!");
                     //driver.close();
                     //driver.quit();
              } catch (Exception e) {
                     System.out.println(e.toString());
                     System.out.println("Test Case Failed!!!");
              }
       }
}

emulator1

References:
http://selenium.polteq.com/en/running-tests-on-an-android-simulator/
http://www.slideshare.net/venkatauday24/mobile-webautomation-using-selenium20-14892310
http://stackoverflow.com/questions/1554099/why-is-the-android-emulator-so-slow

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s