Selenium RC 用户定义函数

发布于 2024-09-19 18:09:01 字数 833 浏览 4 评论 0原文

尝试做一些简单的事情 - 我有一组语句来清除浏览器 cookie:

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

现在,如果我在测试脚本中使用此函数(使用 TestNG),则调用此函数可以完美地工作。但是,如果我将此函数移至单独的类并将声明更改为包含“static”,则无法识别“selenium”关键字。

在配置类(例如 configClass)中,

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

现在,在我的测试脚本中,如果我调用 configClass.clearCookies(); ,我会收到运行时错误 我尝试在clearCookies()函数中声明DefaultSelenium selenium = new DefaultSelenium(null);,但这也会导致运行时错误。

我的 configClass 中确实有 import com.thoughtworks.selenium.*; 导入。

任何指示将不胜感激。谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2024-09-26 18:09:01

你可以做两件事。

在两个类(即 configClass 和您调用 configClass.clearCookies() 的类)中引用相同的 selenium 对象。

或者

将 selenium 对象发送到clearCookies。所以代码就像这样

public static void clearCookies (DefaultSelenium selenium) {

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

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文