[英]Assert Fails Even Though It Shouldn't
I have the following two asserts which are checking the checked
attribute of a check box: 我有以下两个断言,它们正在检查
checked
属性:
Assert.assertEquals(true, notificationCheck.getAttribute("checked").equals(true));
Assert.assertEquals(true, accessCheck.getAttribute("checked").equals(true));
I have setup a sort of debugging where it spits out to console the value of the checked
attribute and they both say true. 我已经设置了一种调试方法,可以在其中调试控制台
checked
属性的值,并且它们都说是正确的。
The error that I am getting is below: 我收到的错误如下:
java.lang.AssertionError: expected [false] but found [true]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertEquals(Assert.java:123)
at org.testng.Assert.assertEquals(Assert.java:286)
at org.testng.Assert.assertEquals(Assert.java:296)
at ui_Tests.ParticipantsPage_AddParticipant.participantPage_AddParticipant(ParticipantsPage_AddParticipant.java:305)
at ui_Tests.ParticipantsPage_AddParticipant.test_participantPage_AddParticipant_FF(ParticipantsPage_AddParticipant.java:315)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
What am I doing wrong? 我究竟做错了什么?
I removed the .equals(true)
from both of the Asserts. 我从两个断言中都删除了
.equals(true)
。 Now I am getting the same error only now it says expected [true] but found [true]
现在,我只得到了
expected [true] but found [true]
错误, expected [true] but found [true]
Most likely you're mixing up data types... what type does notificationCheck.getAttribute("checked") return?? 您最有可能混淆了数据类型... notificationCheck.getAttribute(“ checked”)返回的是哪种类型? I suppose it does not return a Boolean but a String and that's why your test fails.
我想它不会返回布尔值,而是一个字符串,这就是测试失败的原因。 In that case you could try this:
在这种情况下,您可以尝试以下操作:
Assert.assertEquals(true, notificationCheck.getAttribute("checked").equals("true"));
Even better: 更好的是:
Assert.assertEquals("true", notificationCheck.getAttribute("checked"));
If its saying expected true and found true that means: The type might be different. 如果其说法为true且为true,则表示:类型可能不同。 eg : what its getting is
boolean-true
and checking if its equal with String-"true"
or vice versa. 例如:它得到的是
boolean-true
并检查其是否等于String-"true"
,反之亦然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.