简体   繁体   中英

Unable to merge multiple classes in Extent Report in selenium java

I am trying to merge multiple test cases from various classes into one extent report. All test cases are running successfully but it is not adding those test cases into my extent report. The version of my Extent Report is 2.41.2.It is showing the previous extent report only, No new report showing all the test cases is generated. I am successfully generating a single class report but not able to generate multiple classes extent report. Here is my code:

// First I have created a base class for Extent Report:
public static ExtentHtmlReporter htmlReporter;
    public static ExtentReports extent;
    public static ExtentTest test;

    @BeforeSuite
    public void setUp()
    {
        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        extent.setSystemInfo("OS", "Mac Sierra");
        extent.setSystemInfo("Host Name", "Krishna");
        extent.setSystemInfo("Environment", "QA");
        extent.setSystemInfo("User Name", "Krishna Sakinala");

        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
        htmlReporter.config().setReportName("My Own Report");
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setTheme(Theme.DARK);
    }
     @AfterSuite
    public void tearDown()
    {
        extent.flush();
    }
    }
// Now Logintestcase Extending Base Extent report class:
public class LoginTestCase extends ExtentReportBaseClass {

    static WebDriver driver;
    Homepage login = new Homepage();
    UtilityMethods util = new UtilityMethods();

    String locUsernameElem;
    String locPasswordelem;
    String Sign_in;
    String insertEmail;
    String insertFirstName;
    String createAccountButton;

    // @Parameters("browser")

    @BeforeClass
    public void launchBrowser() {

        driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);

        UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
        driver.manage().window().maximize();

    }

    @Test
    public void registration() throws InterruptedException {
        test = extent.createTest("registration", "This will check status for registration of the user.");
        Sign_in = Utility.ConstantsValues.SIGN_IN;
        insertEmail = Utility.ConstantsValues.EMAIL_ADDRESS;
        createAccountButton = Utility.ConstantsValues.CREATE_ACOUNT;
        // insertFirstName=ConstantsValues.USER_FIRSTNAME;
        util.clickElement(Sign_in);
        Thread.sleep(2000);
        // driver.findElement(By.xpath("//input[@id='email_create']")).sendKeys("vivekkumar9652gmail.com");

        util.sendData(insertEmail);
        util.clickElement(ConstantsValues.CREATE_ACCOUNT);
        util.clickElement(ConstantsValues.USER_TITLE);
        util.sendDataById("customer_firstname", ConstantsValues.FIRST_NAME);
        util.sendDataById("customer_lastname", ConstantsValues.LAST_NAME);
        // util.sendData(ConstantsValues.LAST_NAME);
        util.sendData(ConstantsValues.USER_PASSWORD);
        util.clickElement(ConstantsValues.USER_NEWSLETTER);
        Select day = new Select(driver.findElement(By.id("days")));
        day.selectByValue("1");
        Select month = new Select(driver.findElement(By.id("months")));
        month.selectByValue("2");
        Select year = new Select(driver.findElement(By.id("years")));
        year.selectByValue("2014");

        util.sendData(ConstantsValues.USER_COMPANY);


        util.sendData(ConstantsValues.USER_STATE);

        util.sendData(ConstantsValues.USER_ADDRESS1);
        util.sendData(ConstantsValues.USER_MOBILENUMBER);
        util.sendData(ConstantsValues.USER_ZIPCODE);
        util.sendData(ConstantsValues.USER_ALIAS);
        util.sendData(ConstantsValues.USER_CITY);

        util.clickElement(ConstantsValues.SUBMITACCOUNT);
        util.clickElement(ConstantsValues.USER_SIGN_OUT);

        test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
    }

    @Test
    public void userLogin() {
        test = extent.createTest("userLogin", "This will check status for login of the user");
        // util.clickElement(ConstantsValues.SIGN_IN);
        util.sendData(ConstantsValues.LOGIN_USERNAME);
        util.sendData(ConstantsValues.LOGIN_PASSWORD);
        util.clickElement(ConstantsValues.USER_SIGNIN_Account);
        //Assert.assertNotEquals("Krishna", "Krishna");
        test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.RED));
    }


}

//Now another class Extending BaseExtentReport Class:
public class PurchaseItemTestCase extends ExtentReportBaseClass {
    WebDriver driver;

    UtilityMethods util = new UtilityMethods();

    // @Parameters("browser")
    @BeforeClass
    public void launchBrowser() throws InterruptedException {

        System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
        driver = new ChromeDriver();
        driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);

        UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
        driver.manage().window().maximize();

    }

    @Test

    public void chkPurchaseItem() throws InterruptedException {
        test = extent.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
        driver.findElement(By.xpath("//img[@title='Faded Short Sleeve T-shirts']")).click();

        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id,'fancy')]")));

        System.out.println("after frame");
        Thread.sleep(4000);
        driver.findElement(By.xpath("//button[@type='submit']//span[contains(.,'Add')]")).click();
        Set handles = driver.getWindowHandles();

        System.out.println(handles);

        // Pass a window handle to the other window

        for (String handle1 : driver.getWindowHandles()) {

            System.out.println(handle1);

            driver.switchTo().window(handle1);

            Thread.sleep(3000);
            driver.findElement(By.xpath("//a[@title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
            Thread.sleep(3000);
            driver.findElement(By.xpath(
                    "//a[@class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[@class='icon-chevron-right right']"))
                    .click();
            driver.findElement(By.id("email")).sendKeys("vivekkumar009@gmail.com");
            driver.findElement(By.id("passwd")).sendKeys("vivek123");
            Thread.sleep(3000);
            // UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
            driver.findElement(By.id("SubmitLogin")).click();
            driver.findElement(By.name("processAddress")).click();
            driver.findElement(By.id("cgv")).click();
            driver.findElement(By.xpath("//button[@name=\"processCarrier\"]")).click();
            driver.findElement(By.className("cheque")).click();
            driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();

            test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));

        }

    }

}

Make your extent test as thread local variable. Example:

Public ThreadLocal<ExtentTest> test;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM