java试图分配较弱的访问权限错误(java attempting to assign weaker access privilege error)

编程入门 行业动态 更新时间:2024-10-27 02:23:25
java试图分配较弱的访问权限错误(java attempting to assign weaker access privilege error) [javac] U:\dms-webui-testing\test-java\dmswebui\CR\TestLogin.java:16: until() in cannot override until() in com.thoughtworks.selenium.Wait; attempting to assign weaker access privileges; was public

我得到一个相当简单的代码上面的错误:

package dmswebui.CR; import org.infineta.webui.selenium4j.MainTestCase; public class TestLogin extends MainTestCase { @Override public void setUp() throws Exception { super.setUp(); startSeleniumSession("ChromeDriver", "somesite"); } public void testMethod() throws Exception { new Wait("") {boolean until() {return false;}};session().open("/"); new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button"); session().waitForPageToLoad("30000"); for (int second = 0;; second++) { if (second >= 60) fail("timeout 'waitForTextPresent:Logoff' "); try { if (session().isTextPresent("Logoff")) break; } catch (Exception e) {} Thread.sleep(1000); } new Wait("") {boolean until() {return false;}};session().click("id=btnUserLogout-button"); new Wait("") {boolean until() {return false;}};session().click("id=yui-gen0-button"); session().waitForPageToLoad("30000"); } public void tearDown() throws Exception { super.tearDown(); closeSeleniumSession(); } }

这里是我如何使用Wait类。 请帮我理解这个错误。

[javac] U:\dms-webui-testing\test-java\dmswebui\CR\TestLogin.java:16: until() in cannot override until() in com.thoughtworks.selenium.Wait; attempting to assign weaker access privileges; was public

I am getting above error for a fairly simple code:

package dmswebui.CR; import org.infineta.webui.selenium4j.MainTestCase; public class TestLogin extends MainTestCase { @Override public void setUp() throws Exception { super.setUp(); startSeleniumSession("ChromeDriver", "somesite"); } public void testMethod() throws Exception { new Wait("") {boolean until() {return false;}};session().open("/"); new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button"); session().waitForPageToLoad("30000"); for (int second = 0;; second++) { if (second >= 60) fail("timeout 'waitForTextPresent:Logoff' "); try { if (session().isTextPresent("Logoff")) break; } catch (Exception e) {} Thread.sleep(1000); } new Wait("") {boolean until() {return false;}};session().click("id=btnUserLogout-button"); new Wait("") {boolean until() {return false;}};session().click("id=yui-gen0-button"); session().waitForPageToLoad("30000"); } public void tearDown() throws Exception { super.tearDown(); closeSeleniumSession(); } }

here is how I use Wait class. Please help me to understand this error.

最满意答案

有问题的线是以下两条

new Wait("") {boolean until() {return false;}};session().open("/"); new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button");

您尝试通过仅包可见的until方法覆盖com.thoughtworks.selenium.Wait类中具有public访问权限的until方法。

您无法覆盖方法并降低可视性。 您只能增加可见性(例如覆盖protected方法并将其public )

所以解决方法是将public关键字添加到这些方法中

new Wait("") {public boolean until() {return false;}};session().open("/"); new Wait("") {public boolean until() {return false;}};session().click("id=btnLogin-button");

The lines with the problem are the two below

new Wait("") {boolean until() {return false;}};session().open("/"); new Wait("") {boolean until() {return false;}};session().click("id=btnLogin-button");

You try to override the until method which has public access in the com.thoughtworks.selenium.Wait class by a until method which is only package visible.

You cannot override a method and reduce visibility. You can only increase the visibility (e.g. overriding a protected method and making it public)

So the fix would be to add the public keyword to these methods

new Wait("") {public boolean until() {return false;}};session().open("/"); new Wait("") {public boolean until() {return false;}};session().click("id=btnLogin-button");

更多推荐

本文发布于:2023-07-27 15:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:较弱   访问权限   分配   错误   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!