0

I have built a small test framework that uses Selenium Grid and TestNG and I would like to make it support parallel execution reporting with ExtentReports 3 and create a local dynamically-named file based on the name of the TestSuite that will be run. The final ideea would be to run a TestSuite containing multiple classes that each contain 1 test only, defined by the @Test annotation.

<suite>
 <test name="environment1">
  <parameter name="X" value="Y"/>
 <classes>
  <class name="Class containing Test A"/>
  <class name="Class containing Test B"/>
  <class name="Class containing Test C"/>
 </classes>
 </test>
</suite>

The tests are UI tests and the whole suite of tests might take about 2 hours to complete. When a TestSuite is completed an ExtentReport html report would be generated, containing the results of each test.

What I want to do, is start running a test suite, and then start to run another identical test suite in parallel to the first one's execution, but on a different environment and when they finish I want to have 2 different reports. Currently, if I try to do this simply, one report will override the other.

Could someone please give me some directions on how I could achieve this goal?

I have tried implementing the example shown here: http://extentreports.com/docs/versions/3/java/#extent-testng-report-builder however, Eclipse notifies me that The method createNode(String) is undefined for the type Object enter image description here

Below, I am providing my Base Test Configuration file:

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;

public class TestSuiteBase {
    protected WebDriver driver;
    protected SearchPageFactory search;
    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/MyReport.html");
        System.out.println(System.getProperty("user.dir"));
        extent = new ExtentReports();
        extent.attachReporter(htmlreporter);
    }

    @Parameters({ "platform","browser", "url" })
    @BeforeClass(alwaysRun=true)
    public void setup(String platform, String browser, String url) throws MalformedURLException
    {       
        driver = getDriverInstance(platform, browser, url);
        search = PageFactory.initElements(driver, SearchPageFactory.class);
    }

    public static WebDriver getDriverInstance(String platform, String browser, String url)
            throws MalformedURLException {

        String nodeURL = "http://localhost:4444/wd/hub";
        WebDriver driver = null;
        DesiredCapabilities capabilities = new DesiredCapabilities();

        // Platforms
        if (platform.equalsIgnoreCase("Windows")) {
            capabilities.setPlatform(Platform.WINDOWS);
        }
        if (platform.equalsIgnoreCase("MAC")) {
            capabilities.setPlatform(Platform.MAC);
        }
        // Browsers
        if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
        }
        if (browser.equalsIgnoreCase("firefox")) {
            capabilities = DesiredCapabilities.firefox();
        }
        if (browser.equalsIgnoreCase("ie")) {
            capabilities = DesiredCapabilities.internetExplorer();
        }

        driver = new RemoteWebDriver(new URL(nodeURL), capabilities);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        // Open the Application
        driver.get(url);
        return driver;
    }

    @AfterMethod
    public void getResult(ITestResult result) {
        if (result.getStatus()== ITestResult.FAILURE) {
            test.fail(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.RED));
            test.fail(result.getThrowable());
        } else if (result.getStatus()== ITestResult.SUCCESS){
            test.pass(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.GREEN));
        } else {
            test.skip(MarkupHelper.createLabel(result.getName() + " Test case failed ", ExtentColor.YELLOW));
            test.skip(result.getThrowable());
        }
    }

    @AfterSuite
    public void testDown() {
        extent.flush();
    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }
}

I am new to programming and the automation landscape so, any help or suggestions on this endeavor, in particular or in general, would be greatly appreciated. Thank you in advance!

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
JustNatural
  • 375
  • 7
  • 19

1 Answers1

0

It may happen if you have supply Same report name to your each class, Give Different name to each report as according to Class functionality.

All these three classes should contain unique Report name,

 <class name="Class containing Test A"/>
 <class name="Class containing Test B"/>
 <class name="Class containing Test C"/>
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51