limited time offer

Selenium Assertions Interview Questions

Showing 1 - 3 of 3 results

What is soft assertion in Selenium? How can you mark a test case as failed by using soft assertion?

Soft Assertions are customized error handlers provided by TestNG. Soft Assertions do not throw exceptions when assertion fails, and they simply continue to the next test step. They are commonly used when we want to perform multiple assertions.

To mark a test as failed with soft assertions, call assertAll() method at the end of the test.

@Test
public void myTest() 
{
    SoftAssert softAssert = new SoftAssert();
    softAssert.assertTrue("");
    softAssert.assertTrue("");
    softAssert.assertAll();
}

How to assert the title of the web page using Selenium?

Use below code to Assert the title of the Web Page, first you need to get the title using getTitle() functions then use equals() method to compare title with your string. Later, Assert it using assertTrue():

//Method 1
Assert.assertTrue(driver.getTitle().equals("Title of the page"));
//Method 2
Assert.assertTrue("Expected Title", driver.getTitle.getText());

What is the assertion in Selenium?

The assertion is used as a verification point in Selenium. It verifies that the state of the application is as expected. 

The three types of assertion are:

  1. assert
  2. verify
  3. waitFor

We can also use TestNG SoftAssert with Selenium.

Subscribe to Selenium Assertions Interview Questions