jeudi 15 octobre 2020

extentTestLogs are not prinitng in extentReport

I want to report test logs in test reports. I have called the extentReportManager utility in ItestListner and in Test class too. When the extent report object called in test class, the test is not executed, only the browser opens. However, when it calls only in Itestlistner test executes. But testName only prints in report

Could anyone help with this

TestClass

 package com.selenium.tests;

import static org.testng.Assert.assertEquals;

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.selenium.pageObjects.DashBoard;
import com.selenium.pageObjects.RecentActivity;
import com.selenium.pageObjects.Setting;
import com.selenium.pageObjects.SignIn;
import com.selenium.resources.ExtentReportManager;
import com.selenium.resources.base;

import junit.framework.Assert;

public class IcarxTests extends base {
    public WebDriver driver;
    SignIn signIn;
    String getTitle;
    DashBoard dashboard;
    RecentActivity recentActivity;
    ExtentReports extent = ExtentReportManager.getExtentReport();
    public ExtentTest test;

    @BeforeTest
    public void intializeDriver() throws IOException {

        driver = browserIntilization();
        test.info("browser is launched sucessfully");

        driver.get(prop.getProperty("Application_url"));
        test.info(prop.getProperty("Application_url") + "is launched successfully");
    }

    @Test(priority = 1)
    @Parameters({ "Market", "Language" })
    public void setting(String marketStr, String languageStr) throws IOException, InterruptedException {
        System.out.println("1 test");

        Setting setting = new Setting(driver);
        setting.selectMarket(marketStr);
        test.info(marketStr + "is selected");
        setting.selectLanguage(languageStr);
        test.info(languageStr + "is selected");
        Thread.sleep(5000);
        signIn = setting.navigateSignIn();
        test.info("Navigated to signIn page sucessfully");
        getTitle = signIn.getPageTitle();
        Assert.assertEquals("ICAR-X", getTitle);
        test.log(Status.PASS, "Sigin page tile" +getTitle+" is verified");
    }

    @Test(priority = 2)
    @Parameters({ "dealerID", "userID", "password" })
    public void login_Success(String dealerStr, String userIDStr, String passwordStr) throws InterruptedException {
        System.out.println("2 test");

        signIn.enterDealerID(dealerStr);

        signIn.enterUserID(userIDStr);

        signIn.enterPassword(passwordStr);

        dashboard = signIn.naviagateDashBoard();
        Thread.sleep(5000);

    }

ExtentReport utility

package com.selenium.resources;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;


public class ExtentReportManager {
    
    public static ExtentSparkReporter reporter;
    public static ExtentReports extent;
    public static ExtentTest test;
    
    public static ExtentReports getExtentReport() {
        
        String filePath = System.getProperty("user.dir")+"\\reports\\extentReport.html";
        ExtentSparkReporter reporter = new ExtentSparkReporter(filePath);
        reporter.config().setDocumentTitle("Automation Test Report");
        reporter.config().setReportName("ICAR Test Automation Report");
        reporter.config().setTheme(Theme.STANDARD);
        ExtentReports extent = new ExtentReports();
        extent.attachReporter(reporter);
                
        return extent;
    }

}

    **ITestListenr code**
    
   

 package com.selenium.listeners;

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.selenium.resources.ExtentReportManager;
import com.selenium.resources.base;

public class Listeners extends base implements ITestListener {
    
    ExtentReports extent = ExtentReportManager.getExtentReport();
    public ExtentTest test;
    

    @Override
    public void onFinish(ITestContext arg0) {
        extent.flush();
        
    }

    @Override
    public void onStart(ITestContext arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void onTestFailure(ITestResult result) {
        test.fail(result.getThrowable());
        String testMethod = result.getMethod().getMethodName();
        WebDriver driver = null;
        try {
            driver =(WebDriver)result.getTestClass().getRealClass().getDeclaredField("driver").get(result.getInstance());
        } catch(Exception e)
        {
            
        }
        
        try {
            String destinationPath = getScreenShotPath(testMethod, driver);
            
            test.addScreenCaptureFromPath(destinationPath, testMethod);
            
            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        test.log(Status.FAIL, testMethod + "Test is Failed");
        
    }

    @Override
    public void onTestSkipped(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test.log(Status.SKIP, testMethod);
        
        
    }

    @Override
    public void onTestStart(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test = extent.createTest(result.getMethod().getMethodName());
        test.log(Status.PASS, testMethod + "Test is Started");
        
        
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        String testMethod = result.getMethod().getMethodName();
        test.log(Status.PASS, testMethod + "Test is Passed");
        
    }

}

Aucun commentaire:

Enregistrer un commentaire