Go to Site http://appium.io/
Download Appium for Windows
Install Node JS
https://nodejs.org/download/release/latest/
Update the APIs
To Update API
Open Eclipse
Click on Window in the Eclpise Menu and Select Andoird SDK manager
Update the APIs
Set The JAVA_HOME
ANDROID_HOME--> C:\Users\NEERAJ\Desktop\adt-bundle-windows-x86_64-20140321\sdk
Update path with tools and platform-tools (folder present in Adnroid sdk)
Now Entry in Path will look like follwoing
C:\Program Files\nodejs\;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
Now in CMD run --->adb
adb will be accessible
Download Contact Manager.apk
https://github.com/appium/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk
Install the contact Manager.apk in the device
INstall Apk.info App from Google Play Store i.e this app will help us in identfying the app-package and app-activity
Run Appium.exe
Now run the following Sample program to test
package com.gurpreet.project;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class appium {
WebDriver driver;
@BeforeClass
public void setUp() throws Exception {
File app = new File("C:\\Users\\NEERAJ\\Downloads", "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("deviceName","Moto G");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app-package", "com.example.android.contactmanager-1");
capabilities.setCapability("app-activity", ".ContactManager");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testApp() throws MalformedURLException{
System.out.println("App launched");
// locate Add Contact button and click it
WebElement addContactButton = driver.findElement(By.name("Add Contact"));
addContactButton.click();
//locate input fields and type name and email for a new contact and save it
List<WebElement> textFieldsList = driver.findElements(By.className("android.widget.EditText"));
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(1).sendKeys("9999999999");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.findElement(By.name("Save")).click();
//insert assertions here
}
}
Download Appium for Windows
Install Node JS
https://nodejs.org/download/release/latest/
Update the APIs
To Update API
Open Eclipse
Click on Window in the Eclpise Menu and Select Andoird SDK manager
Update the APIs
Set The JAVA_HOME
ANDROID_HOME--> C:\Users\NEERAJ\Desktop\adt-bundle-windows-x86_64-20140321\sdk
Update path with tools and platform-tools (folder present in Adnroid sdk)
Now Entry in Path will look like follwoing
C:\Program Files\nodejs\;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
Now in CMD run --->adb
adb will be accessible
Download Contact Manager.apk
https://github.com/appium/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk
Install the contact Manager.apk in the device
INstall Apk.info App from Google Play Store i.e this app will help us in identfying the app-package and app-activity
Run Appium.exe
Now run the following Sample program to test
package com.gurpreet.project;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class appium {
WebDriver driver;
@BeforeClass
public void setUp() throws Exception {
File app = new File("C:\\Users\\NEERAJ\\Downloads", "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.2");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("deviceName","Moto G");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app-package", "com.example.android.contactmanager-1");
capabilities.setCapability("app-activity", ".ContactManager");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testApp() throws MalformedURLException{
System.out.println("App launched");
// locate Add Contact button and click it
WebElement addContactButton = driver.findElement(By.name("Add Contact"));
addContactButton.click();
//locate input fields and type name and email for a new contact and save it
List<WebElement> textFieldsList = driver.findElements(By.className("android.widget.EditText"));
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(1).sendKeys("9999999999");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.findElement(By.name("Save")).click();
//insert assertions here
}
}
No comments:
Post a Comment