Pre-Requisites:
- Have a knowledge on TestNG. Refer TestNG Tutorial
Procedure:
- Prepare a TestNG Test Case (Appium_TestNG_Sample_One) class file
- This will be as below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package appium_Package; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import org.testng.annotations.AfterMethod; public class Appium_TestNG_Sample_One { @Test public void f() { } @BeforeMethod public void beforeMethod() { } @AfterMethod public void afterMethod() { } } |
Here is the XML file
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite" > <test name="Test"> <classes> <class name="appium_Package.Appium_TestNG_Sample_One"/> </classes> </test> <!-- Test --> </suite> <!-- Suite --> |
- Launch Amazon Application using TestNG
- I’m going to use Set Up Appium Project in Eclipse code to use in the TestNG
It looks like the below code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
package appium_Package; import org.testng.annotations.Test; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import org.testng.annotations.BeforeMethod; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterMethod; public class Appium_TestNG_Sample_One { private static AndroidDriver<MobileElement> driver; @Test public void f() { } @BeforeMethod public void beforeMethod() throws MalformedURLException, InterruptedException { File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "/Apps/Amazon/"); File app = new File(appDir, "in.amazon.mShop.android.shopping.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("deviceName", "Micromax A311"); capabilities.setCapability("platformVersion", "4.4.2"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "in.amazon.mShop.android.shopping"); capabilities.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity"); driver = new AndroidDriver<MobileElement>(new URL("https://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); Thread.sleep(10000); } @AfterMethod public void afterMethod() { } } |
Run this TestNG class after launching Appium server by right clicking on the TestNG.xml–>RunAs–>TestNG Suite
Here is the Screenshot below for reference