rs79
rs79

Reputation: 2321

Selenium RC User Defined Functions

Trying to do something simple - I have a set of statements to clear browser cookies:

public void clearCookies () {
     selenium.open("http://www.myurl.com");
     selenium.waitForPageToLoad("10000");
     selenium.deleteAllVisibleCookies();
    }

Now, if I use this function in a test script (using TestNG), calls to this work perfectly. However, if I moved this function to a separate class and change the declaration to include "static", the "selenium" keyword is not recognized.

In a configuration class (say configClass),

public static void clearCookies () {
     selenium.open("http://www.myurl.com");
     selenium.waitForPageToLoad("30000");
     selenium.deleteAllVisibleCookies();
    }

Now, in my test script, if I call configClass.clearCookies();, I get a runtime error I tried declaring DefaultSelenium selenium = new DefaultSelenium(null);, in the clearCookies() function, but that too results in a runtime error.

I do have the import com.thoughtworks.selenium.*; import in my configClass.

Any pointers would be appreciated. Thanks.

Upvotes: 0

Views: 817

Answers (1)

Sel--ium Automater
Sel--ium Automater

Reputation: 36

You can do two things.

Refer to the same selenium object in both the classes i.e. in configClass and the class you are calling configClass.clearCookies().

or else

send selenium object to the clearCookies. So the code would be like this

public static void clearCookies (DefaultSelenium selenium) {

 selenium.open("http://www.myurl.com");
 selenium.waitForPageToLoad("30000");
 selenium.deleteAllVisibleCookies();

}

Upvotes: 1

Related Questions