Thursday, 21 May 2015

Appium Java - Executing 'Appium-Webdriver' automation script on mobile device

This session demonstrates automating the script for 'EriBank' app and executing the automation script in mobile device.

Prerequisites(previous session):
Watch the video sessions in the below URL's
1. http://automation-home.blogspot.in/2015/05/appium-installation.html
2. http://automation-home.blogspot.com/2015/05/appium-overview-deviceversions-and-apilevels.html
3. http://automation-home.blogspot.com/2015/05/appium-uiautomatorviewer.html

Video Session covers below topics:
- Automating EriBank App
- Authoring script without using Junit/TestNG
- Capabilities
   * deviceName
   * platformVersion
   * app
      - capabilities.setCapability("app",System.getProperty("user.dir")+"/apk/EriBank.apk");
   * appPackage
   * appActivity
- AndroidDriver (in earlier version it is 'AppiumDriver')
   * driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
- Executing the automation script in the mobile device.

Sample Program:
package pack1;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

public class TestEriBank {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
        AppiumDriver driver;
     
        DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","");
//capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("app",System.getProperty("user.dir")+"/apk/EriBank.apk");

capabilities.setCapability("appPackage", "com.experitest.ExperiBank");
capabilities.setCapability("appActivity", ".LoginActivity");

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

driver.findElement(By.id("com.experitest.ExperiBank:id/usernameTextField")).sendKeys("company");
driver.findElement(By.id("com.experitest.ExperiBank:id/passwordTextField")).sendKeys("company");
driver.findElement(By.id("com.experitest.ExperiBank:id/loginButton")).click();

driver.findElement(By.id("com.experitest.ExperiBank:id/logoutButton")).click();

Thread.sleep(3000);
driver.quit();
}
}

Note: 
   For executing the above program 'apk' folder should be created in the eclipse project and 'EriBank.apk' file should be placed in the 'apk' folder of the eclipse project.
   'Eribank.apk' can be downloaded from 'http://code.google.com/p/eribank/downloads/list'
 
Watch Demo

4 comments:

  1. informative and good reference for beginners

    ReplyDelete
  2. hi Praveen suggest where I get One plus one phone driver?

    ReplyDelete
    Replies
    1. If you are unable to find the mobile device drivers at url http://www.mobiledit.com/downloads.htm?show=14

      Install PdaNet for installing mobile device drivers, which are not available at url http://www.mobiledit.com/downloads.htm?show=14.

      PdaNet download url http://pdanet.co/

      Watch below video for installing pdanet for usb mobile device drivers.
      https://www.youtube.com/watch?v=iNyifEQBh3E
      https://www.youtube.com/watch?v=YYB9klmKUTM

      Delete