Assertions in Selenium
Assertions in Selenium
IN SELENIUM
Definition:
assertNotEquals
assertTrue
assertFalse
assertNull
assertNotNull
assertAll()
assertEquals:
This is used to compare expected and
actual values in selenium webdriver.
Whenever the expected and actual
values are same, the assertion passes
with no exception. But, if the actual
and expected values are not just same,
the assert fails with an exception and
the test is marked as “failed”. The
suite continues to run with the next
@Test annotation(if any).
Assert.assertEquals(actual,expected);
assertNotEquals:
assertNotEquals is just opposite to
the functioning of assertEquals
assertion. Whenever the expected and
actual values matches, the assertion
fails with an exception and marks the
test-case as “failed”. The particular
testcase is aborted and execution
continuous with the next @Test
annotation.
Assert.assertNotEquals(actual,expected,
Message);
assertTrue:
When we are dealing with Boolean
conditions, we should use
assertTrue. This assertion returns
true if the applied condition
passes. If the condition is
false/fails, this assertion skips
the current method from execution.
Assert.assertTrue(condition);
assertFalse:
Assert.assertFalse checks the
Boolean value returned by a
condition is false or not. When a
condition value is true, the
assertion aborts the method by an
exception. This is basically
opposite to assertTrue.
Assert.assertFalse(condition);
assertNull:
This assertion checks for a
object, if it is null or not.
When an object is ‘null’ the
assertion returns an exception
resulting in aborting the test.
Assert.assertNull(object);
assertNotNull:
Assert.assertNotNull is vice-versa
of assertNull. When a object has
some value, the assertion aborts
the method with an exception.
Assert.assertNotNull(object);
assertAll:
When using assertAll(), it allows you to
verify all the assertions made in a test
case, and it collects all the assertion
errors in a single test case, instead of
failing the test immediately when an
assertion fails. This allows you to see
all the assertion errors in one go, which
can be helpful for troubleshooting and
debugging.