开发者

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开发者_JAVA技巧.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.


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

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜