0

我在 @AfterSuite 注释中有 Define , driver.quit 。在我的 TestNG XML 中,我配置了 Extent Report Listener。现在,当测试失败时,驱动程序关闭并且报告生成失败,并出现以下错误“[TestNG] Reporter com.ufe.ExtentReportListener.ExtentReportListerner@1832aa failed org.openqa.selenium.NoSuchSessionException: Session ID为空。在调用 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();
}
4

0 回答 0