public class ExtentReports_Basecode {
static Random rand = new Random();
static long drand = (long)(rand.nextDouble()*10000000000L);
public WebDriver dr;
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;
private static String filePath = "D://" + drand + "ExtentReports_Bindu.html";
@BeforeSuite
public void setup() {
htmlReporter = new ExtentHtmlReporter(filePath);
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS", "Windows10");
extent.setSystemInfo("Host Name", "Bindu");
extent.setSystemInfo("Environment", "rose");
extent.setSystemInfo("User Name", "1234_ws");
//htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("Favourite Automation Report");
htmlReporter.config().setTheme(Theme.DARK);
}
@BeforeMethod
public void startTest(Method m)
{
test = extent.createTest(m.getName(),"This is the description of Test" + m.getName());
}
@AfterMethod
public static void getResult(ITestResult result){
if(result.getStatus()== ITestResult.FAILURE){
test.log(Status.FAIL,MarkupHelper.createLabel(result.getName() + "Test case FAILED due to below issues:",ExtentColor.RED));
test.fail(result.getThrowable());
}
else if(result.getStatus()== ITestResult.SUCCESS){
test.log(Status.PASS,MarkupHelper.createLabel(result.getName() + "Test Case PASSED",ExtentColor.GREEN));
}
else{
test.log(Status.SKIP,MarkupHelper.createLabel(result.getName() + "Test Case Skipped",ExtentColor.YELLOW));
test.skip(result.getThrowable());
}
}
@AfterSuite
public void teardown(){
extent.flush();
}
}
脚本1:
public class sc1 extends ExtentReports_Basecode{
public WebDriver dr;
public Report report = null;
String inputSheetPath ="TestData/InputData/DataSheet.xls" ;
@BeforeTest
public void launchBrowser() {
System.out.println("launching Chrome browser");
dr = Driver.getChromeDriver();
}
@Test
private void sc1_95_Fav(){
System.out.println("sc1"); }
}
}
Script2:
public class sc2 extends ExtentReports_Basecode{
public WebDriver dr;
public Report report = null;
String inputSheetPath ="TestData/InputData/DataSheet.xls" ;
@BeforeTest
public void launchBrowser() {
System.out.println("launching Chrome browser");
dr = Driver.getChromeDriver();
}
@Test
private void sc2_83_Fav() {
}
}
}
TestNG XML:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--<suite name="Parallel test Suite">-->
<suite name="My suite" parallel="classes" thread-count="10">
<test name="name">
<classes>
<!-- To Add Any Class start -->
<class name="OpenUI.Favourites.sc1"/>
<class name="OpenUI.Favourites.sc2"/>
<!--To Add Any Class End -->
</classes>
</test>
</suite>
在范围报告中,我在第二个测试用例中得到结果..有人可以建议我错过了哪里以及如何使用TestNG使用范围报告并行测试正确地看到输出。 As shown in the image the results output of first Test is shown in the second Test, if any thing get failed the Failed output shown in Last Test not in actual failed Test PS:当我使用testNG逐个顺序运行时,它的工作正常。
答案 0 :(得分:0)
遵循此模式,希望您的问题得到解决
WebDriver driver;
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
@BeforeTest
public void setUp() {
// where we need to generate the report
htmlReporter = new ExtentHtmlReporter("Your report Path");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("Rehomes");
htmlReporter.config().setReportName("Rehomes Production Testing");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
}
@Test
public void HomepageLogo() throws Exception {
test = extent.createTest("rentalhomesHomePage");
//Your Test
}
@AfterMethod
public void setTestResult(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL, result.getName());
test.log(Status.FAIL,result.getThrowable());
//test.fail("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, result.getName());
//test.pass("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SKIP) {
test.skip("Test Case : " + result.getName() + " has been skipped");
}
extent.flush();
driver.close();
}
}
答案 1 :(得分:-1)
感谢您的答复,但不幸的是,上述一项艰苦的工作,如果以这种方式尝试,只能给出一份作为报告生成的测试。您能提出其他解决此问题的方法吗?