tags:

views:

66

answers:

1

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.

A: 

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();

}

Sel--ium Automater