hi @Bilal_Jarwan
1.code for appium loader main class
package AppiumLaunch;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.automationtesting.excelreport.Xl;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
public class AppiumTest implements AutoConstant {
public static WebDriver appium;
{
}
@BeforeTest
public void Test() throws InterruptedException, MalformedURLException
{
// Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
// caps.setCapability(“deviceName”, “My Phone”);
// caps.setCapability(“udid”, “192.168.238.101:5555”); // Give Device ID of your mobile phone
// caps.setCapability(“platformName”, “Android”);
// caps.setCapability(“platformVersion”, “7.1.0”);
// caps.setCapability(“appPackage”, “ebroker.com.ebroker”);
// caps.setCapability(“appActivity”, “ebroker.com.ebroker.ui.login.LoginActivity”);
// caps.setCapability(“automationName”,“UiAutomator2”);
// caps.setCapability(“noReset”, “true”);
caps.setCapability ("appActivity", "ebroker.com.ebroker.ui.login.LoginActivity");
caps.setCapability ("appPackage", "ebroker.com.ebroker");
caps.setCapability ("automationName","UiAutomator2");
caps.setCapability ("deviceName", "My Phone");
caps.setCapability ("noReset", "true");
caps.setCapability ("platformName", "Android");
caps.setCapability ("platformVersion", "7.1.0");
caps.setCapability ("udid", "192.168.155.101:5555");
// Instantiate Appium Driver
appium = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
appium.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
@AfterTest
//quite
public static void closeAndroid()
{
if (appium != null)
{
appium.quit();
}
}
- code for TestListner
package POC_Concept;
import java.io.IOException;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import AppiumLaunch.AppiumTest;
import AppiumLaunch.AutoConstant;
import AppiumLaunch.Lib;
public class TestListner extends TestListenerAdapter implements AutoConstant
{
String values = "";
static int count = 1;
@Override
public void onTestStart(ITestResult result)
{
System.out.println("Test has started running:" + result.getMethod().getMethodName() + " at:" + result.getStartMillis());
}
@Override
public void onTestFailure(ITestResult result)
{
System.out.println("Log Message:: @AfterTest: " + result.getMethod().getMethodName() + " has Failed");
values = "FAIL";
captureScreenshot(AppiumTest.appium, result.getMethod().getMethodName());
try {
Lib.setColumnValue(TEST_EXCEL_PATH1, "EBROKER", count, 6, values);
} catch (IOException | InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count++;
}
@Override
public void onTestSuccess(ITestResult result) {
System.out.println("Log Message:: @AfterTest: " + result.getMethod().getMethodName() + " has Passed");
values = " PASS ";
try {
// System.out.println(Lib.getCellValue(EXCEL_PATH, "Valid_Login", 1,
// 1));
Lib.setColumnValue(TEST_EXCEL_PATH1, "EBROKER", count,6, values);
// System.out.println(Lib.getCellValue(EXCEL_PATH, "Valid_Login", 1,
// 1));
} catch (IOException | EncryptedDocumentException | InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count++;
}
@Override
public void onTestSkipped(ITestResult result)
{
System.out.println("Log Message:: @AfterTest: " + result.getMethod().getMethodName() + " has Skipped");
}
public static String captureScreenshot(WebDriver driver, String screenshotName) {
try
{
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File ("./screenshots/"+ screenshotName + ".jpg"));
return new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date());
}
catch (Exception e)
{
System.out.println("Exception while taking screenshot " + e.getMessage());
}
return screenshotName;
}
}