0

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();
1

Just replace your code using this may this help you:

  public class CommonAssertion{
   public static String verifyLocationOnViewReport(){
      String countryText= null;
      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));
          countryText=verifyCountry.getText();
          System.out.println(countryText); 

          return countryText;

      }
      catch(Exception e){
          System.out.println("Country not found");

      }
      return countryText;

      }
}


    @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();  

In your case you was trying to compare Boolean value with String value because your method has returned the Boolean value that's why your test case fail.
Here my example is base on comparing String value, but if you want compare with Boolean value then try to use assertTrue method in place of assertEquals.

3

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.

  • It doesnt return string, but I have to verify report filter criteria choosen at new report page should be same with view report page. – jay Jun 14 at 13:07
  • I have added assertequals() method but first argument it take as webelement and scond as a String, So I am confused it will return String or WebElement – jay Jun 14 at 13:09
  • It wont return anything based on its argument types. It will return whatever its return type is. I think you're trying to run before you can walk here. It may be worthwhile to spend some time getting familiar with the basics of Java before continuing. Become familiar with the concept of the "return type". – anonygoose Jun 14 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.