assertequals() returns true but make my test case failed



  • I have added assertion(Assert.assertEquals(condition,"expected","message")), it returns true then also it gives an error and make my testcase failed, with Assertion error and message? Can any one help me if its returning true why it failed my rest of the test cases.

    Below is my code:

    CommonAssertion class:

    public class CommonAssertion{
    public static boolean verifyLocationOnViewReport(){
                try{
    
                //  WebElement checkCarat=Driver.getDriver().findElement(By.xpath(PageUtility.SELECT_NEXT_LEVEL));
                //  checkCarat.click();
                    WebElement verifyCountry=Driver.getDriver().findElement(By.xpath(PageUtility.LOCATION_TEXT_VR));
                    String countryText=verifyCountry.getText();
                    System.out.println(countryText); 
    
                    return true;
    
                }
                catch(Exception e){
                    System.out.println("not matched");
    
                }
                return false;
    
                }}
    
    
    @Test
    @Test(priority = 6)
        public void clickOnViewReportButton() throws Exception {
            System.out.println("1");
            System.out.println(CommonAssertion.verifyLocationOnViewReport());
            Assert.assertEquals(CommonAssertion.verifyLocationOnViewReport(), "United States", "united states not found");
            createNewReportBusiness.clickOnViewReport();
    


  • Looking at your code, you appear to be asserting that a string and a boolean value are equal. That isn't going to work!

    This is what you're doing, essentially:

    assertEquals(true, "United States");
    

    Either use assertTrue, or have your verifyLocationOnViewReport method return a string that you can compare to the known value.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2