Start with Appium ---> Appium
1. Download the following,
i. appium from, appium
ii. node.js from, Nodejs
iii. Install JAVA and JAVA_HOME to your jdk path and add jdk path to your PATH
iv. Have Android SDK installed and set ANDROID_HOME to be your Android SDK path and add tools and platform-tools folders to your PATH and the API level should be >= 17
vi. install Apache Maven from, Maven and set M2HOME to your Maven folder and M2 to your bin folder of Maven and add M2 to your PATH
vii. selenium standalone server
2. Have the Webdriver script ready, create a java project and add the selenium jar to the project and make sure testng is installed on your eclipse.
Example code to start with appium
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
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;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AppiumTest {
private WebDriver driver;
@BeforeMethod
public void setupAppium() throws MalformedURLException
{
File appDir = new File("Path of your .apk file");
File app = new File(appDir, "{Appname.apk}");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME,""); // if you are automating the web app you should mention the Browser name, empty string is used since automating the mobile app.
capabilities.setCapability(CapabilityType.VERSION, "4.2");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOW");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app-package", "{packagenameofyourapp}"); //my case com.xxxxxx.yyy.demo1
capabilities.setCapability("app-activity", "{activitynamofurapp}");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
@Test
public void test()
{
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.id("yourelementid")).sendKeys("Username");
driver.findElement(By.id("yourelementid")).sendKeys("Password");
driver.findElement(By.id("yourelementid")).click();
driver.findElement(By.id("yourelementid")).click();
}
}
NOTE : To find the package and activty name of your apk file, open the command path and go to path where you have your apk file and run this command "aapt dump badging yourpkg.apk"
Use the id with full package name for eg. "com.name.pckgname.activity.yourelementid"
4. Launch your Appium server, Go to the folder where Appium is installed, click on the Appium.exe,
Click on the Andoird icon in the top left corner and check application path and choose the path wher your .apk file is located.
If you are running on real device uncheck the Launch AVD and check the Device name and set it as Android.
Click on the settings icon and check the set the server Adress and port as 127.0.0.1 and 4723 respectively.
Click on Launch the "Appium Node Server".
NOTE: if you are running on real device make sure that you have connected your device using USB cable and open your command prompt and check the list of devices attached by using the command "adb devices"
if you are running on emulator start your emulator before you run your script.
Now, run your script, the app should launch on the mobile device connected to your machine.
Good Start Pavithra Ravichandran....keep Up
ReplyDelete