-
Notifications
You must be signed in to change notification settings - Fork 314
How to configure Extent Reports for Appium Parallel execution? Am getting null pointer exception ! #1113

Description
Implementing Appium grid when am performing parallel execution the application and catching null pointer exception
Summary
Expected Behavior
Current Behavior
It was working perfectly when I was working to execute single test case but when am doing the same for parallel it's throwing me null pointer exception
Sample
// Sample code goes here
public class AppiumTestBase {
public static final Logger log = Logger.getLogger(AppiumTestBase.class.getName());
static AppiumDriverLocalService services;
public static AndroidDriver<MobileElement> driver;
public static String destDir;
public static String srcPath;
Capablities caP;
static AppiumServer aS;
public static ExtentReports extent;
public static ExtentTest test;
public ITestResult result;
public static String newFileName;
public ExtentReports reo =ExtentManager.getInstance();
public static ExtentTest tst;
static {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
extent = new ExtentReports(System.getProperty("user.dir") + "\target\surefire-reports\html\"+ formater.format(calendar.getTime()) + ".html", false);
extent.loadConfig(new File(System.getProperty("user.dir") + Configration.ReportsConfig));
}
public String captureScreen(String fileName) {
if (fileName == "") {
fileName = "blank";
}
File destFile = null;
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
String reportDirectory = new File(System.getProperty("user.dir")) + "\target\surefire-reports\html\";
destFile = new File(
(String) reportDirectory + fileName + "_" + formater.format(calendar.getTime()) + ".png");
newFileName = fileName + "_" + formater.format(calendar.getTime()) + ".png";
FileUtils.copyFile(scrFile, destFile);
Reporter.log("<a href='" + destFile + "'> <img src='" + "_" + fileName + formater.format(calendar.getTime())
+ ".png" + "' height='100' width='100'/> </a>");
}
public void log(String data) {
log.info(data);
Reporter.log(data);
}
public void getresult(ITestResult result) {
if (result.getStatus() == ITestResult.SUCCESS) {
test.log(LogStatus.PASS, result.getName() + "test is pass");
captureScreen("");
test.log(LogStatus.PASS, test.addScreenCapture(newFileName));
} else if (result.getStatus() == ITestResult.SKIP) {
test.log(LogStatus.SKIP,
result.getName() + " test is skipped and skip reason is:-" + result.getThrowable());
captureScreen("");
test.log(LogStatus.SKIP, test.addScreenCapture(newFileName));
} else if (result.getStatus() == ITestResult.FAILURE) {
test.log(LogStatus.ERROR, result.getName() + " test is failed" + result.getThrowable());
captureScreen("");
test.log(LogStatus.FAIL, test.addScreenCapture(newFileName));
} else if (result.getStatus() == ITestResult.STARTED) {
test.log(LogStatus.INFO, result.getInstanceName() + "test is started" + result.getThrowable());
}
}
@Parameters({ "deviceName_","UDID_","platformVersion_" })
// @BeforeMethod()
// public void beforeMethod(Method result) throws MalformedURLException {
//AppiumServer.start();
//driver =Capablities.setAndroidCapablities(driver);
@BeforeMethod
public AndroidDriver<MobileElement> beforeMethod(String deviceName_,String UDID_,String platformVersion_) throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", deviceName_);
capabilities.setCapability("udid", UDID_);
capabilities.setCapability("platformVersion", platformVersion_);
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.hitesh_sahu.retailapp");
capabilities.setCapability("appActivity", "com.hitesh_sahu.retailapp.view.activities.LoginActivity");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
test = extent.startTest(result.getName());
test.log(LogStatus.INFO, "open Application");
return driver;
}
@AfterClass(alwaysRun = true)
public void endTest() {
extent.endTest(test);
extent.flush();
}
public void reportLog(String message) {
captureScreen("");
test.log(LogStatus.INFO, message+ test.addScreenCapture(newFileName));// at this ponit am getting nullpointer execption
log.info("Message: " + message);
Reporter.log(message);
}
}
This is my test case
public class Test_FireCart_Dashboard_module extends AppiumTestBase{
Dashboard_module dM;
@Test(priority = 1)
public void testMenuFunctionality() throws InterruptedException {
try {
dM = new Dashboard_module(driver);
PageFactory.initElements(new AppiumFieldDecorator(driver), dM);
reportLog("Verify Fire Cart Application is launched");
dM.signUp_with_google();
dM.googleacc();
reportLog("Verify Sign in with google button is clicked");
new WebDriverWait(driver, 1000l)
.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.hitesh_sahu.retailapp:id/header")));
reportLog("Verify user sucessfully login to Fire Cart dashboard");
dM.clickOnMenu();
reportLog("Verify menu button is clicked");
for(int i =2;i<=6;i++) {
reportLog("Verify user clicked" + dM.clickMenuItems().get(i).getText());
dM.clickMenuItems().get(i).click();
dM.clickOnBack();
dM.clickOnMenu();
}
new WebDriverWait(driver, 1000l)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='Logout']")));
dM.clickOnLogout();
reportLog("Verify Logout option is clicked");
} catch (Exception e) {
reportLog("Failed to launch Fire cart application");
}
try {
String act_text = HardAssertions.textassertion(dM.validateLoginScreen());
Assert.assertEquals(act_text, "LOGIN");
} catch (Exception e) {
captureScreen("");
test.log(LogStatus.FAIL, "Filed to logout from Fire cart dashbord", test.addScreenCapture(newFileName));
}
}
Environment Details
- Extent report Version used: 2.41.2
- Operating System and version: Windows 10 pro
- JDK Version: java version "1.8.0_161"
Screenshots
java.lang.NullPointerException