简体   繁体   中英

Selenium TestnNg - where should AssertAll() be placed in the test

I am working on Page Object Model framework in the Selenium -TestNG using Java in Eclipse IDE. I have my base class, pages and test classes ready. In my test, I am using SoftAssert class as I want my test to continue even when they fail. In the end I do SoftAssert.assertAll().

Everything works fine.

But ideally where should assertAll method be executed?

  1. In the last test method (@Test) which is going to get executed in that class? 2)AfterClass 3)AfterSuite

As per ur comment @AfterTest? what you meant by @AfterTest?

@BeforeTest and @AfterTest are respective to test (<test>... </test>) in testng.xml file

simply use SoftAssert softAssertion= new SoftAssert(); at start of @Test and softAssertion.assertAll(); at end

@Test
public void softAssert(){
    SoftAssert softAssertion= new SoftAssert();
    //..............
    //..............
    softAssertion.assertAll();
}

go through doc to learn more on testng https://testng.org/doc/documentation-main.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM