[英]Extent report test status recording for failure
I am trying to execute tests and using Extent report to integrate my tests for reporting purpose.我正在尝试执行测试并使用范围报告来集成我的测试以用于报告目的。 I wrote test.log pass status only.
我只写了 test.log 通过状态。 Not getting how to log failure too keeping in mind I am using assert to validate.
记住我正在使用断言进行验证,但没有得到如何记录失败。
public class Logintest extends Basetest {
Loginpage ls;
Homepage hpg;
@BeforeMethod
public void setup() {
initialization();
ls = new Loginpage();
hpg = new Homepage();
}
@DataProvider
public Object[][] validcredentialsdataprovider() throws Exception {
Test_Util ts = new Test_Util();
return ts.excelutil(0);
}
@DataProvider
public Object[][] invalidcredentialsdataprovider() throws Exception {
Test_Util ts = new Test_Util();
return ts.excelutil(1);
}
@Test(priority = 1)
public void verifysuccessfullogin() throws Exception {
hpg = ls.clickonloginbtn();
String actualtitle = hpg.gettitle();
String expectedtitle = "Guru99 Bank Manager HomePage";
Assert.assertEquals(actualtitle, expectedtitle)
test.log(LogStatus.PASS, "Test passed");
}
@Test(priority = 2, dataProvider = "validcredentialsdataprovider")
public void verifyloginwithvaliddata(String un, String pword) throws Exception {
ls.verifyloginthroughdatadrivenapproach(un, pword);
Assert.assertEquals(hpg.gettitle(), "Guru99 Bank Manager HomePage");
test.log(LogStatus.PASS, "Test passed");
}
@Test(priority = 3, dataProvider = "invalidcredentialsdataprovider")
public void verifyloginwithinvaliddata(String un, String pword) throws Exception {
ls.verifyloginthroughdatadrivenapproach(un, pword);
Test_Util.forcedwait(5);
String s = driver.switchTo().alert().getText();
Assert.assertEquals(s, "User or Password is not valid");
driver.switchTo().alert().accept();
Test_Util.forcedwait(2);
test.log(LogStatus.PASS, "Test passed");
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
Please help.I tried various things like using ITestResult listener but it is failing and returning null every time I try to execute.请帮助。我尝试了各种方法,例如使用 ITestResult 侦听器,但每次尝试执行时它都会失败并返回 null。 I tried testResult.getStatus()==ITestResult.SUCCESS, testResult.getStatus()==ITestResult.FAILURE in if else condition but did not work.
我在 if else 条件下尝试了 testResult.getStatus()==ITestResult.SUCCESS, testResult.getStatus()==ITestResult.FAILURE 但没有奏效。
When you assert something - you need to "write" it into the report object.当您断言某事时 - 您需要将其“写入”到报告 object 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.