我在@AfterSuite注释中具有Define,driver.quit。在我的TestNG XML中,我已经配置了范围报告侦听器。现在,如果万一测试失败,则驱动程序将关闭,并且报告生成将因以下错误而失败 “ [TestNG]报告程序com.ufe.ExtentReportListener.ExtentReportListerner@1832aa失败 org.openqa.selenium.NoSuchSessionException:会话ID为null。调用quit()后使用WebDriver吗?”
但是如果通过测试,就会生成报告。
代码:- 公共类OrderSubmissionTest扩展了TestBase {
public OrderSubmissionTest(){
super();
}
@BeforeTest()
public void setup() throws InterruptedException, IOException ,NullPointerException{
initialization();
LogInPage=new LogInPage();
}
@Test(priority=1/*dependsOnMethods="CreateCustomerTest"*/)
public void Login_Initiate_Sales() throws IOException, InterruptedException {
searchCustomer=LogInPage.Login(prop.getProperty("Username"), prop.getProperty("Password"));
salesPage=searchCustomer.InitiateSales();
createCustomer=salesPage.AddtoBasket();
}
@DataProvider
public Object[][] getUFE_Data() throws IOException{
Object Data[][]=TestUtil.TestData(TestUtil.Sheetname);
return Data;
}
@Test(priority=2,dataProvider="getUFE_Data",/*retryAnalyzer=com.ufe.util.RetryAnalyzer.class,*/dependsOnMethods="Login_Initiate_Sales")
public void CreateCustomerTest(String Fname, String Lname,String dob,String PIN, String address, String No, String Email) throws InterruptedException, IOException {
createCustomer.CreateContact(Fname, Lname, dob, PIN, address, No, Email);
Thread.sleep(2000);
salesPage=createCustomer.CreateBillingProfile(Lname, Lname,Fname+Lname, Fname+Lname, Email);
}
@Test(priority=3,dependsOnMethods="CreateCustomerTest",enabled=false)
public void AddToBasket() throws IOException, InterruptedException {
salesOfferPage=salesPage.AddAgain();
System.out.println(salesOfferPage.Write_Select_Offer());
delivery_page=salesOfferPage.Select_Attribute();
}
@Test(priority=4,dependsOnMethods="AddToBasket",enabled=false)
public void DeliveryScreenTest() throws IOException, InterruptedException {
delivery_page.validate_delivery_page();
billingProfileScreen=delivery_page.delivery_type();
}
@Test(priority=5,dependsOnMethods="DeliveryScreenTest",enabled=false)
public void BillingProfileValidation() throws IOException, InterruptedException {
billingProfileScreen.validate_Billing_page();
billingProfileScreen.DisableCreditVetting();
salesConfirmationScreen=billingProfileScreen.UpdateBillingProfile();
}
@Test(priority=6,dependsOnMethods="BillingProfileValidation",enabled=false)
public void FlowSubmissionTest() throws IOException, InterruptedException {
orderSubmission=salesConfirmationScreen.validate_Confirmation_page().Proceed_To_NextOrSubmit();
orderSubmission.ValidateOrderSubmission().Order_Submission();
}
@AfterMethod
public void status(ITestResult result) throws IOException{
if(result.getStatus()==ITestResult.FAILURE) {
TestUtil.TakeScreenShot(result.getMethod().getMethodName());
}
}
@AfterSuite()
public void tear_down() {
driver.quit();
}