Styrow.dev
Question 14 of 14
TestNG Topic: General medium

How to use assertions in TestNG explain with one example?

Question

How to use assertions in TestNG explain with one example?

Answer

There are many different assertions available In TestNG but few important assertions are:

assertEquals assertNotEquals assertTrue assertFalse assertNull assertNotNull

Assert.assertEquals(actual, expected): This assertion is used to compare expected and actual values in selenium WebDriver. If both values are same then it will continue execution. But if fails then immediately it will mark the test method as fail and exit from that test method.

Sample Code:

@Test public void assertCheck(){ WebDriver driver=new FirefoxDriver(); driver.navigate().to(""http://gmail.com""); Assert.assertEquals(""Gmail"", driver.getTitle()); }

The above test will pass since both value matches.