如何解决在 Cucumber 框架中作为 TestNG 运行时,ExtentReports 将所有测试用例的测试名称显示为“runScenario”
我已将现有的 Selenium-TestNG 框架转换为 Cucumber,并且正在使用 ExtentReports 进行报告。我在 Listeners 类中截取屏幕截图。当我将测试作为 TestNG 测试运行时,我的所有 screeshots 都会被覆盖,并且范围报告将所有测试用例的测试名称显示为“runScenario”:
我想为范围报告中的所有测试场景显示功能文件场景名称,而不是“runScenario”,并防止覆盖屏幕截图。
Feature: logout feature
Background:
Given User is on Salesforce login page
@SmokeTest @Low @PositiveTest @logout
Scenario: logout of application1
Given "RMUser" has logged into Salesforce application
When User clicks on logout button
Then Users is logged-out from the application
@SmokeTest @Low @PositiveTest @logout
Scenario: logout of application2
Given "RMUser" has logged into Salesforce application
When User clicks on logout button
Then Users is logged-out from the application
运行文件:
package cucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = "src/test/java/featuresCommon",glue = "stepDeFinitions",tags="@logout",//tags="@Login and @SanityTest",//tags="@SanityTest or @SmokeTest",//tags="not @SanityTest",dryRun = false,monochrome = true,plugin = {
"pretty","json:target/cucumber-reports/Cucumber.json","html:target/cucumber-reports/Cucumber.html","junit:target/cucumber-reports/Cukes.xml"
}
)
public class TestNGRunner extends AbstractTestNGCucumberTests{
}
监听器类:
public class Listeners extends Base implements ITestListener {
ExtentReports extentReport = ExtentReporterNG.getExtentReportObj();
ExtentTest test;
public void onTestStart(ITestResult result)
{
test = extentReport.createTest(result.getmethod().getmethodName());
}
public void onTestSuccess(ITestResult result)
{
test.log(Status.PASS,"Test case Passed");
try
{
String path = takeScreenshot(driver,"Pass/" + result.getInstanceName() + "/" + result.getmethod().getmethodName());
test.addScreenCaptureFromPath(path,result.getmethod().getmethodName());
}
catch (Exception e)
{
log.fatal("Exception in onTestSuccess Method of Listeners class");
log.fatal(e.getMessage() +" : " + e.getStackTrace());
System.out.println("Exception " + e.getMessage());
System.out.println("Exception " + e.getStackTrace());
}
driver.quit();
}
public void onTestFailure(ITestResult result) {
test.log(Status.FAIL,"Test case Failed");
test.fail(result.getThrowable());
try
{
String path = takeScreenshot(driver,"Fail/" + result.getInstanceName() + "/" + result.getmethod().getmethodName());
test.addScreenCaptureFromPath(path,result.getmethod().getmethodName());
}
catch(Exception e)
{
log.fatal("Exception in onTestFailure Method of Listeners class");
log.fatal(e.getMessage() +" : " + e.getStackTrace());
System.out.println("Exception " + e.getMessage());
System.out.println("Exception " + e.getStackTrace());
}
driver.quit();
}
public void onFinish(ITestContext context) {
// Todo Auto-generated method stub
extentReport.flush();
}
Base File(截屏的相关截图方法):
public static String takeScreenshot(WebDriver driver,String testcaseName) throws IOException {
String destinationPath = System.getProperty("user.dir") + "/screenshots/" + testcaseName + ".png";
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src,new File(destinationPath));
return destinationPath;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。