24
[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.

hrishikeshp19
  • 8,838
  • 26
  • 78
  • 141

1 Answers1

31

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");
Robin
  • 36,233
  • 5
  • 47
  • 99
  • one second early than Keppil. Thanks both of you. :) – hrishikeshp19 Jul 24 '12 at 23:05
  • Yes, you mean I can only increase the visibility. overriding a protected method and making it public, but not package. I think package modifier can increase the visibility of protected one, am I right for this understanding? – Chao Mar 23 '15 at 03:45
  • 2
    @Richard no that is not correct. Protected methods are visible for all subclasses, also subclasses outside the package. So making it package visible would increase visibility for some cases (another class in the same package), but reduce visibility as well in other cases (subclass in another package). – Robin Mar 23 '15 at 10:32
  • Easily said, javac won't compile it, so it is not totally an expansion of visibility. – WesternGun Jun 08 '17 at 17:01