[英]Issue with assertion in webdriver and TestNG
I am facing a wired situation while doing an assertion. 我在做断言时正面临困境。 I am asserting the value inside each list (Lists are supposed to contain same value even though that are not List of same objects) 我在每个列表中声明该值(即使列表不是相同对象的列表,列表也应该包含相同的值)
Here is my assertion code : 这是我的断言代码:
for (int i=0 ; i< rst.size(); i++)
{
Assert.assertSame(l.get(i).getName(),rst.get(i).getText());
Here is the response I am getting : 这是我得到的答复:
FAILED: srch("tsk", "http://frstmwarwebsrv2.orsyptst.com:9000/duobject? searchString=TSK&filtercheck=nameSWF&p.index=0&p.size=8")
java.lang.AssertionError: expected [TSK(ACE700J)(000)(ACE700JU00)(000)] but found [TSK(ACE700J)(000)(ACE700JU00)(000)]
}
I have changed the above as advised by I am still getting the same error : 我已经按照我的建议更改了上述内容,但仍然遇到相同的错误:
Assert.assertSame ((l.get(i).getName().trim()), rst.get(i).getText().trim());
The methods getName()
and getText()
both return Strings, so (assuming your problem is only leading and trailing white space) all you need to do is add .trim()
, like so: 方法getName()
和getText()
都返回String,因此(假设您的问题只是空格的.trim()
,您需要做的就是添加.trim()
,如下所示:
Assert.assertEquals(l.get(i).getName().trim(),rst.get(i).getText().trim());
It seems, also, that what you want to do is test that different objects in memory are meaningfully equal . 同样,您似乎想做的就是测试内存中的不同对象是否有意义地相等 。 This means you want to use assertEquals()
, not assertSame()
. 这意味着您要使用assertEquals()
而不是assertSame()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.