简体   繁体   English

断言即使不应该失败

[英]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.

相关问题 Android执行if语句,即使它不应该执行? - Android executing an if statement even though it shouldn't ever execute? 为什么 Java *sort* HashMap 条目即使不应该这样做? - Why does Java *sort* HashMap entries even though it shouldn't? JSP页面发布表单,即使它不应该-验证错误? - JSP page posting form even though it shouldn't - validation error? 即使资源不存在也获得响应 - Getting response even though the resource shouldn't exist 每个for循环都会在新行上打印,即使不应 - Every for loop prints on a new line, even though it shouldn't 应用程序绕过登录屏幕(即使不应该这样做) - App Bypassing the Login-screen, even though it shouldn't 即使具有相同的数据,断言也无法比较两个数据类 - Assert fails in comparing two data classes even though the have same data 对象输入流类强制转换异常-即使不应该发生 - Object Input Stream Class cast exception - even though it shouldn't happen Java Future.isDone返回true,即使它不应该,它会停止程序进度 - Java Future.isDone returning true, even though it shouldn't, which halts program progress 即使我的类路径中有JUnit jar,Tomcat也找不到“ org.junit.Assert” - Tomcat doesn't find “org.junit.Assert” even though I have JUnit jars in my classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM