@Elias_Nogueira you are wrong . yes it works in parallel.
lets see how it is work:
// baseTest class
public class BaseTest {
private Process appium_Process;
protected static AppiumDriver driver = null;
private static DesiredCapabilities capabilities = null;
private static String fileName = "ApiDemos-debug.apk";
private static String userDir = "/src/test/java/resources";
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext iTestContext) throws Exception {
System.out.println("BeforeSuite: ");
// start appium here if needed ( or use any remote url e.g. for selenium grid)
}
@BeforeMethod(alwaysRun=true)
public void beforeMethod(Object[] testArgs, Method method, ITestContext iTestContext) throws Exception {
System.out.println("BeforeMethod: ");
// now open driver to needed url
capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM);
// .... other capabilites
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterMethod(alwaysRun=true)
public void afterMethod(ITestResult iTestResult, ITestContext iTestContext) throws Exception {
System.out.println("AfterMethod: ");
// take screenshot if failed and quit driver
try {
driver.quit();
} catch (Exception e) {}
}
@AfterTest(alwaysRun=true)
public void afterTest(ITestContext iTestContext) throws Exception {
System.out.println("AfterTest: ");
// do if needed something e.g. print number of passed and failed test. useful to see how it goes with large suites
}
@AfterSuite(alwaysRun=true)
@Parameters({"generateReport"})
public void tearDown(ITestContext iTestContext, @Optional String generateReport) throws Exception{
System.out.println("AfterSuite: ");
System.out.println("===============================================");
System.out.println(" passed tests: "+iTestContext.getPassedTests().size());
System.out.println(" skipped tests: "+iTestContext.getSkippedTests().size());
System.out.println(" failed tests: "+iTestContext.getFailedTests().size());
System.out.println("===============================================\n");
// kill appium if needed
}
}
// now lets see some tests!
public class test_1 extends BaseTest { // see here we extending! BaseTest with ALL it's power of testNG annotations.
private MainPage mainPage;
@Test
public void foundViews_Sweep() {
mainPage = new MainPage(driver);
assertTrue("Main screen NOT loaded", mainPage.isMainPageLoaded());
assertTrue("'Views' cell NOT found", mainPage.tapCellByTitle("Views"));
assertTrue("Header title NOT Correct", mainPage.getHeaderText().equals("API Demos"));
// Sweep does not exist. Example of failed test.
assertTrue("'Sweep' cell NOT found", mainPage.tapCellByTitle("Sweep"));
assertTrue("Header title NOT Correct", mainPage.getHeaderText().contains("Sweep"));
}
@Test
public void foundViews_WebView() {
mainPage = new MainPage(driver);
assertTrue("Main screen NOT loaded", mainPage.isMainPageLoaded());
assertTrue("'Views' cell NOT found", mainPage.tapCellByTitle("Views"));
assertTrue("Header title NOT Correct", mainPage.getHeaderText().equals("API Demos"));
assertTrue("'WebView' cell NOT found", mainPage.tapCellByTitle("WebView"));
assertTrue("Header title NOT Correct", mainPage.getHeaderText().contains("WebView"));
}
}
in @beforeMethod you can accept parameters like in your “/src/test/java/com/eliasnogueira/TipTest.java” and open driver to needed platform and url with any test whatever like.
example:
@BeforeMethod (alwaysRun = true)
@Parameters({"platform", "udid", "platformVersion"})
public void beforeMethod(@Optional String platform, @Optional String udid,
@Optional String platformVersion,
ITestContext iTestContext) throws Exception {
driver = Utils.returnDriver(platform, udid, platformVersion); // here we put your driver start
so your parameters in:
https://github.com/eliasnogueira/appium-parallel-execution/blob/master/suite.xml
will get populated in beforeMethod were you can just add your:
driver = Utils.returnDriver(platform, udid, platformVersion);
and you will not need any more to add into each your test this line cause it will be executed right before test in beforeMethod :-). i updated code.