有没有办法在extent报告中打印测试用例的各个步骤

时间:2017-08-17 05:04:09

标签: extentreports

有没有办法在范围报告中打印测试步骤? 登录测试用例的示例,我想打印

1.输入用户名 2.输入密码 3.点击登录按钮

也许如果在状态,时间戳和详细信息之后,可以添加步骤

1 个答案:

答案 0 :(得分:0)

我在框架中使用ExtentReport,如下面的代码,我对此非常满意。希望,下面的示例代码,适合您

// initialize the HtmlReporter
public ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("C:\\report\\path\\to\\report.html");
// initialize the report
public ExtentReports report  = new ExtentReports();
// initialize the report
public ExtentTest logger ;
//ExtentHtmlReporter and ExtentXReporter allow appending test information to an existing report.
htmlReporter.setAppendExisting(true);
// attach only HtmlReporter
report.attachReporter(htmlReporter);

//Create main test cases
logger = report.createTest("Driver Initialization");

logger.log(Status.INFO, "Starting firefox browser");
System.setProperty("webdriver.gecko.driver", "path\\to\\geckodriver\\geckodriver.exe");
driver = new FirefoxDriver();
logger.log(Status.INFO, "Browser started");

driver.get("www.facebook.com");
logger.log(Status.INFO, "Title is: "+driver.getTitle());

logger.log.(Status.PASS, "Application opened");

driver.findElement(By.id("username")).sendKeys("validuser");
logger.log(Status.INFO, "username entered");

driver.findElement(By.id("password")).sendKeys("validpassword");
logger.log(Status.INFO, "Password entered");

driver.findElement(By.id("login")).click();
logger.log(Status.INFO, "login button clicked");

logger.log(Status.PASS, "Home page opened");

//Simply call the flush() method to write or update test information to your reporter. 
report.flush();

driver.quite();

如果您有任何疑问,请告诉我。