extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
220 stars 126 forks source link

Extentreport not generating in java when test executed using testNG #408

Open reshma-sabu opened 11 months ago

reshma-sabu commented 11 months ago

I am trying to run a Java test and create a extentreport using Listener class, base class and test class.

BaseTest.class

package qatarlivestock.pagefactory.utils;

import java.io.FileInputStream;

import java.io.IOException;

import java.net.URL;

import java.time.Duration;

import java.util.Properties;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.android.options.UiAutomator2Options;

import io.appium.java_client.service.local.AppiumDriverLocalService;

public class BaseTest {

public AndroidDriver driver;

public AppiumDriverLocalService service;

@BeforeClass

public void configAppium() throws IOException{

    Properties prop = new Properties();

    FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//src//main//java//qatarlivestock//testdata//data.properties");

    prop.load(fis);

    String ipAddress = prop.getProperty("ipAddress");

    String deviceName = prop.getProperty("deviceName");

    UiAutomator2Options options = new UiAutomator2Options();

    options.setDeviceName(deviceName);

    options.setApp(System.getProperty("user.dir")+"//src//test//java//qatarlivestock//testresources//app-qa-release_Sep11.apk");

    driver = new AndroidDriver(new URL(ipAddress), options);

    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

}

@AfterClass

public void tearDown() {

    driver.quit();

}

}

Listeners.class

package qatarlivestock.pagefactory.utils;

import java.io.FileInputStream;

import java.io.IOException;

import java.net.URL;

import java.time.Duration;

import java.util.Properties;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.android.options.UiAutomator2Options;

import io.appium.java_client.service.local.AppiumDriverLocalService;

public class BaseTest {

public AndroidDriver driver;

public AppiumDriverLocalService service;

@BeforeClass

public void configAppium() throws IOException{

    Properties prop = new Properties();

    FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//src//main//java//qatarlivestock//testdata//data.properties");

    prop.load(fis);

    String ipAddress = prop.getProperty("ipAddress");

    String deviceName = prop.getProperty("deviceName");

    UiAutomator2Options options = new UiAutomator2Options();

    options.setDeviceName(deviceName);

    options.setApp(System.getProperty("user.dir")+"//src//test//java//qatarlivestock//testresources//app-qa-release_Sep11.apk");

    driver = new AndroidDriver(new URL(ipAddress), options);

    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

}

@AfterClass

public void tearDown() {

    driver.quit();

}

}

ExtentreporterNG.class

package qatarlivestock.pagefactory.utils;

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class ExtentReporterNG {

static ExtentReports extent;

public static ExtentReports getReporterObject()

{

    String path = System.getProperty("user.dir")+"//testreports//result.html";

    ExtentSparkReporter reporter=new ExtentSparkReporter(path);

    reporter.config().setReportName("Android Test Automation Result");

    reporter.config().setDocumentTitle("Test Results");

    extent = new ExtentReports();

    extent.attachReporter(reporter);

    extent.setSystemInfo("Tester", "Reshma");

    return extent;

}

}

SuccessfullLoginTest.class

package qatarlivestock.testcases;

import org.testng.annotations.Test;

import qatarlivestock.pagefactory.android.SuccessfullLoginElements;

import qatarlivestock.pagefactory.utils.BaseTest;

public class SuccessfullLoginTest extends BaseTest{

@Test

public void successfullLoginValidation() throws InterruptedException

{

    SuccessfullLoginElements login = new SuccessfullLoginElements(driver);

    login.clickloginbtn();

}

}