Use Of Hard Assertion In Selenium
Posted By : Manish Kumar | 28-Mar-2018
As we need to check both positive and negative test cases in the script and check for the test cases is passed or failed, but the system should continue running our code to the end and logs all test case results, for this, we use Assertions in Selenium.
assertEquals : Assert.assertEquals(actual,expected); assertTrue : Assert.assertTrue(condition); assertNotEquals: Assert.assertNotEquals(actual,expected,Message); assertFalse : Assert.assertFalse(condition); assertNull: Assert.assertNull(object); assertNotNull: Assert.assertNotNull(object);
<>
@Test
public void testCaseVerifyHomePage() {
driver= new FirefoxDriver();
driver.navigate().to("www.google.com");
System.out.println("Assertion case started");
Assert.assertEquals("Google", driver.getTitle());
System.out.println("Assertion case finished");
}
<>
Assertion case started Assertion case finished
But if the assertion test is failed:
<>
@Test
public void testCaseVerifyHomePage() {
driver= new FirefoxDriver();
driver.navigate().to("www.google.com");
System.out.println("Assertion case started");
Assert.assertEquals("Ggooggllee", driver.getTitle());
System.out.println("Assertion case finished");
}
</>
Assertion case started
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Manish Kumar
Manish is Adaptive and passionate to learn new technical skills, have knowledge of testing and love to play badminton in free time