Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
4.4k views
by The go-to Tester (218 points)
retagged by
I am automating a project using Selenium Webdriver in Java language. I am using extent to generate report. I can generate report using single method but having trouble when there are parallel methods. How can I generate reorts when tests run parallely.
by The go-to Tester (181 points)
Can you explain, what trouble are you facing while using extent with parallel execution?
by The go-to Tester (218 points)
I have written the following code. How can u continue:
        extent = new ExtentReports("file-path", true);  
        ExtentTest test = extent.startTest("My First Test", "Sample description");
        test.log(LogStatus.INFO, " log(logStatus, details)");

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

Here is sample base test and sample test.

BaseTest.java

package test;
 
import java.lang.reflect.Method;
 
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
 
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
 
public class BaseTest extends TestListenerAdapter {
public ExtentTest testReporter;
 
@BeforeMethod
public void beforeMethod(Method caller) {
ExtentTestManager.startTest(caller.getName(), "This is a simple test.");
}
 
@AfterMethod
public void afterMethod(ITestResult result) {
if (result.isSuccess()) {
ExtentTestManager.getTest().log(LogStatus.PASS, "Test passed");
}
else if (result.getStatus() == ITestResult.FAILURE) {
ExtentTestManager.getTest().log(LogStatus.FAIL, "Test failed");
}
else if (result.getStatus() == ITestResult.SKIP) {
ExtentTestManager.getTest().log(LogStatus.SKIP, "Test skipped");
}
 
ExtentTestManager.endTest();
ExtentManager.getInstance().flush();
}
 
@AfterSuite
public void afterSuite() {
ExtentManager.getInstance().flush();
}
}
 
SampleTest.java
 
package test;
 
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
 
public class SampleTest extends BaseTest {
 
 
@Test
public void testApp(){
//testReporter.assignCategory("Smoke");
AssertJUnit.assertTrue(false);
}
 
@Test
public void testApp1(){
AssertJUnit.assertTrue(true);
}
 
@Test
public void testApp2(){
AssertJUnit.assertTrue(false);
}
 
 
@Test
public void testApp3(){
AssertJUnit.assertTrue(true);
}
}
 
These executes in parallel. Let me know if you need more informations.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...