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]

1 Answer 1

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


    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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