1

My TestNG test implementation throws an error despite the expected value matches with the actual value.

Here is the TestNG code:

int rowCount=driver.findElements(By.xpath(prop.getProperty("xpath"))).size();
Assert.assertEquals(rowCount,prop.getProperty("row[]"));

I got the the following error:

java.lang.AssertionError: expected [5] but found [5]
the_coder
  • 754
  • 1
  • 4
  • 13
user25316
  • 11
  • 1
  • 1
  • 2

1 Answers1

4

You are comparing an int to a string. Try converting the type before comparing the values.

import org.testng.Assert;

public class Test
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Integer rowCount = 1;
        String stringValue = "1";
//      Assert.assertEquals(rowCount,stringValue); //this fails

        Assert.assertEquals(rowCount,Integer.valueOf(stringValue)); //this passes


    }
}
jpjwolli
  • 487
  • 2
  • 8