SELENDROID & APPIUM SETUP
1. How to add Android plugin to eclipse
To add the ADT plugin to Eclipse:
2. Start Eclipse, then selectHelpInstall New Software.
3. ClickAdd, in the top-right corner.
4. In the Add Repository dialog that appears, enter "ADT Plugin" for theNameand the following URL for theLocation:
https://dl-ssl.google.com/android/eclipse/
Note:The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS.
5. ClickOK.
6. In the Available Software dialog, select the checkbox next to Developer Tools and clickNext.
7. In the next window, you'll see a list of the tools to be downloaded. ClickNext.
8. Read and accept the license agreements, then clickFinish.
If you get a security warning saying that the authenticity or validity of the software can't be established, clickOK.
9. When the installation completes, restart Eclipse.
10. Download Android sdk zip file from the site http://developer.android.com/sdk/index.html
11. Extract the zip file
12. Install SDK Manager.exe
13. Download the below files from the site http://selendroid.io/
a. Selendroid Standalone with dependencies jar file
b. Selendroid Test App
14. Paste both the above files in platform-tools path
E:\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools
15. Create the below environment variables
ANDROID_HOME: E:\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_05
path: E:\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools
16. Go to eclipse and create the Android project
17. Create Android Virtual devise
18. Start the selendroid server as below
¨ Go the command prompt
¨ type cd E:\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools and click on enter
¨ type E: and press enter
¨ type below command and press enter
java -jar selendroid-standalone-0.15.0-with-dependencies.jar -app selendroid-test-app-0.15.0.apk
Android Program
Run the program from Eclipse
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import junit.framework.TestCase;
public class Gmail {
public WebDriver driver;
@Test
public void login(){
driver=new RemoteWebDriver(DesiredCapabilities.android());
driver.get("http://gmail.com");
driver.findElement(By.id("Email")).sendKeys("testingse2");
driver.findElement(By.id("next")).click();
Thread.sleep(3000);
driver.findElement(By.id("Passwd")).sendKeys("selenium");
driver.findElement(By.id("signIn")).click();
}
}
Appium
We can use the same above files for Appium also. But we need to change the below files
- Instead of Selendroid server we have to start appium server
- we can download it from below site (http://appium.io)
- Instead of selendroid-standalone-0.15.0-with-dependencies.jar file we need to use the below jar files
· Selenium-server-standalone jar file
· selenium java client jar files
· google-gson jar files(https://code.google.com/p/google-gson/downloads/detail?name=google-gson-2.2.4-release.zip&)
· Appium java client jar file (https://github.com/appium/java-client)
package com.example.android.supportv13;
import static org.junit.Assert.*;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class WhatsAPP {
public WebDriver driver;
@Before
public void setUp() throws Exception {
}
@Test
public void test() throws Exception {
//File f=new File("D:\\Whats app\\WhatsApp.apk");
DesiredCapabilities dc=new DesiredCapabilities();
//dc.setCapability(CapabilityType.BROWSER_NAME, "firefox");
dc.setCapability("deviceName", "Samsung");
dc.setCapability("platformVersion", "4.4.2");
dc.setCapability("platformName", "Android");
dc.setCapability("browserName", "Browser");
//dc.setCapability("f", f.getAbsolutePath());
//dc.setCapability("appPackage", "com.whatsapp");
// dc.setCapability("appActivity", "com.whatsapp.Main");
driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),dc);
driver.get("http://gmail.com");
driver.findElement(By.id("Sign In")).click();
driver.findElement(By.id("Email")).sendKeys("testingse2");
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
driver.findElement(By.id("Passwd")).sendKeys("selenium");
driver.findElement(By.id("signIn")).click();
Thread.sleep(2000);
}
@After
public void aftertest(){
//driver.quit();
}
}
IE Xpath:
http://functionaltestautomation.blogspot.in/2008/12/xpath-in-internet-explorer.html