Android Automation <Selenium >
Steps to Configure Selenium Web Driver in Android Device
Download the SDK zip file and unzip in your local computer.
Say download at “C:\android ” location
Go to unzipped folder and click on “Android SDK Manager” and install the following:
a.Tools
b.Extras
c.Android API’s as per your choice (Say Android 2.2 , Android 4.0)
2. Install the ADT Plugin for Eclipse-
Goto Help > Install New Software....>> Add
3.Configure ADT Plugin
Window > Preferences...>>Android
Set the SDK location to where is your Android SDK has been installed.
Location will be something like: C:\android\android-sdk-windows
4. Add the new AVD
In Eclipse goto Window >>AVD Manager>>
Create new AVD by clicking on “New” button.(Give the AVD name and select the Target)
5.Now download the Android APK
Copy the file and paste it in the “Platform-tools” folder of the unzipped Android SDK.
Location will be something like “C:\android\android-sdk-windows\platform-tools “
6. Now start the Android AVD (Which has been created in Step 4) by following below in your Eclipse
Window >>AVD Manager>> Select the created AVD and click on “Start”
Window >>AVD Manager>> Select the created AVD and click on “Start”
7. Find the installed emulator device id .
open the command prompt ( cmd ) and run the following command
open the command prompt ( cmd ) and run the following command
adb devices
Emulator device id will be something like “emulator-5554”
8. Now from the command prompt, go to the “Platform-tools” folder of the unzipped Android SDK
cd "C:\android\android-sdk-windows\platform-tools"
9. Install the Android server by running the following command
adb -s emulator-id -e install -r android-server-2.21.0.apk
10. Start the Android WebDriver application by running the following command
adb -s emulator-id shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity -e debug true
11. Now setup the port forwarding in order to forward traffic from the host machine to the emulator by running the following command
adb -s emulator-id forward tcp:8080 tcp:8080
Create Java Project in Eclipse.
Run this below code :-
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.AndroidDriver;
public class Sampletc {
public static void main(String args[])throws Exception
{
WebDriver ad=new AndroidDriver();
System.out.println("Started");
ad.get("http://www.gmail.com");
System.out.println("Application Title"+ ad.getTitle());
Thread.sleep(2000);
ad.findElement(By.name("Email")).sendKeys("ur mail id");
System.out.println(ad.getTitle());
ad.findElement(By.name("Passwd")).sendKeys("ur password");
ad.findElement(By.name("signIn")).click();
System.out.println("Opened");
//ad.close();
}
}
Note: Port 8080 should be free.
Insdtead od Emulator id we can use attached device Id.
Thanks!!
Aman Saraf Jain
No comments:
Post a Comment