Search code examples
javaseleniumtestngassertassertions

Assertion Advance Specification


public class openbowser {

    public WebDriver driver= null;
    String browser="mozilla";
    String url="https://www.google.com";
    String actualTitle = driver.getTitle(); 
    String expectedTitle = "googleInd"; 
    assert.assertTrue(actualTitle,expectedTitle); 
    Reporter.log("Application Launched successfully ");  
}

When I run the Test, it fails and will show the following error:

java.lang.AssertionError: expected [googleInd] but found [Google]  

Is there any method I can modify the assertion? It should mention details in more plain english.

Example:

java.lang.AssertionError: Expected title "googleInd" but found "Google"

Solution

  • You can use assertEquals(String actual, String expected, String message)

    assert.assertEquals(actualTitle, expectedTitle, "Expected title '" + expectedTitle + "' but found '" + actualTitle + "'");