Friday, January 21, 2011

How to Automate Android using selenium RC

Requirments:
1.Eclipse IDE
2. Selenium jar's , Android Webdriver.apk file.
3.Android SDK .
Steps to create the Script:
1. Install the Android Webdriver in the Emulator with the following command
       
        $android-sdk\tools\adb install android-server-2.apk
2.Start the WebDriver from the Emulator.
3.Open Eclipse Create a New Java Project and paste the below sample program.
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.android.AndroidDriver;
public class android extends TestCase {
public void testGoogle() throws Exception {
AndroidDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http:");
try {
Thread.sleep(10000);
} catch (IllegalMonitorStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Find the text input element by its name
driver.findElement(By.name("what")).sendKeys("pizza");
driver.findElement(By.name("what")).click();
Thread.sleep(3000);
//driver.findElement(By.name("//input[@id='where']")).sendKeys("nyc");
driver.findElement(By.xpath("//input[@id='where']")).sendKeys("nyc");
driver.findElement(By.name("where")).click();
// Enter something to search for
// driver.findElement(By.name("Search")).click();
driver.findElementByXPath("//input[@value='Search']").submit();
// Now submit the form. WebDriver will find the form for us from the element
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}

Note: Keep the Webdriver opened in the Emulator , where u can see the execution of Scripts.

Hope this helps to Automate the HTML5 Build.

2 comments:

  1. i did the say way u said to me.. but i got the error. would you like to share me your eamil address with me so i can send you my error trace. my email is niloy.cit1@gmail.com

    ReplyDelete
  2. Can u Please post your trace out here ...

    ReplyDelete