Testng SoftAssert always returns null

1.1k views Asked by At

I'm using a softassert in testNG from org.testng.asserts.SoftAssert

I'm testing something very basic - the title - just to see if I can get the soft assert to work and to put feedback in the report if it fails. Problem is, in either case where the assertion should pass or fail, it just always returns null.

@Test
void doTest()
{
    driver.get("URL")
    System.out.println(driver.getTitle())
    l_assert.assertEquals(driver.getTitle(), "String")
    l_assert.assertAll()
}

This always returns null

2

There are 2 answers

0
Ruslan Ostafiichuk On

Probably the problem is that you didn't initialize it. You have to have this somewhere:

l_assert = new SoftAssert();
0
Password On

Try to use next example:

l_assert.assertEquals(driver.getTitle(), "String", "Error Message Should Be Here");