I am using SoftAsserts in my test script and I do have a custom listener class which takes screenshot on failure , but when I do the
SoftAsserts -> assertAll() within @AfterTest or @AfterMethod , it fires up my onTestSuccess method in my custom listener class which means that even though there are failures my test is marked as passed , but if I use assertAll() within the same @Test method it works fine.
What I want is rather than declaring assertAll() inside each test method to put it inside a @AfterTest or @AfterMethod , so that it captures the errors and point it to my listener class with failures
public class GoogleTest {
WebDriver driver;
SoftAssert softAssert;
@BeforeMethod
public void setup() {
// Set the path to the chromedriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
// Create a new instance of ChromeDriver
driver = new ChromeDriver();
// Initialize SoftAssert
softAssert = new SoftAssert();
}
@Test(description="Testing Soft Asserts")
public void verifyGoogleTitle() {
// Navigate to Google
driver.get("
https://www.google.com");
// Verify the title using SoftAsserts
softAssert.assertEquals(
driver.getTitle() , "Invalid Title");
}
@AfterMethod
public void tearDown() {
// Perform assertions
softAssert.assertAll();
// Quit the driver
driver.quit();
}
}
Above script when @AfterMethod is executed even though there are failures listener class takes it as passed.
Requesting support on this issue