Wednesday, 1 June 2016

Sample code to Run a APP on Real Device through Appium

Sample code to Run a APP on Real Device through Appium.



This Piece of code tested on -
  • Appium -1.3.4 IOS -6 (8.1)
  •  Mac: Mavericks [10.9.5] 
  • Java -1.7 & 8 
  • TestNG 
  • WebDriver- 2.45

1. Install all the pre-requisites as mentioned above

2. Connect your Iphone and collect your udid through itunes.

3 Turn on the Appium server, you can do it in two ways :
  • Using Appium UI.
  • Through Terminal.
4 In my case, i am using terminal. Enter "appium -U xxxxxxxxxxxxxxxxxxxxxxxxx  --app /path/to/app/" command in your terminal. This will set the server on.
     
       xxxxxxxxxxxxxxxxxxxxxxx : Stands for UDID of your Device 

Note : you can add more arguments in the command like --address 127.0.0.1 and --port 4723.
           if you face any error.

5. Now you are all set to run your code.

6. Code : Java code written in Eclipse.


package runapp;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;


public class testapp {
 WebDriver wd;

 @BeforeTest
 public void beforeTest() throws MalformedURLException { 
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "iPhone 6");
  capabilities.setCapability("platformName", "iOS");
  capabilities.setCapability("platformVersion", "8.1");
  capabilities.setCapability("app", "/path/to/app/");  //Path of Safari.app 
  capabilities.setCapability("udid", "xxxxxxxxxxxxxxxxxxx");

  wd = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  wd.manage().timeouts().implicitlyWait( 10,TimeUnit.SECONDS);
 }

 @Test
 public void clickonapp() throws InterruptedException {

wd.findElement(By.id("Login")).click();
  
 }

 @AfterTest
 public void afterTest() {
  wd.close();
 } 
}   



7.Run this code.

8.Check Terminal window, wheather system is pushing some commands or not .


Looking for your feedback. All The Best.


**************************Enjoy Automation****************************

No comments:

Post a Comment