java SeleneseTestCase 已弃用 - 如何调用 verify* 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5094598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SeleneseTestCase is deprecated - how to call verify* methods?
提问by Mason
When I use the code generated by the JUnit 4 formatter in the Selenium IDE, I get warnings that the class SeleneseTestCase is deprecated - makes sense since it's supposed to b JUnit 4 syntax and use annotations instead of deriving from a test class.
当我在 Selenium IDE 中使用 JUnit 4 格式化程序生成的代码时,我收到警告说 SeleneseTestCase 类已被弃用 - 这是有道理的,因为它应该使用 JUnit 4 语法并使用注释而不是从测试类派生。
The issue is when I modify my code to not extend SeleneseTestCase I'm not sure how to call the verify* methods - they appear to only exist in the deprecated class. I can run my selenium actions using the code below but verifyTrue is undefined. What is the correct way to call the verify methods in Selenium 2.0b2?
问题是当我修改我的代码以不扩展 SeleneseTestCase 时,我不确定如何调用 verify* 方法 - 它们似乎只存在于已弃用的类中。我可以使用下面的代码运行我的 selenium 操作,但 verifyTrue 未定义。在 Selenium 2.0b2 中调用验证方法的正确方法是什么?
private static Selenium selenium;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://testurl.com/");
selenium.start();
}
@Test
public void testLogin() throws Exception {
selenium.open("/test.html");
verifyTrue(selenium.isTextPresent("Please Sign In"));
.....
采纳答案by CarlosZ
I think the idea is for you to use JUnit's Assert.assertXXX()
the difference is that verifyXXX
will fail during teardown instead of immediately but I think with Selenium tests you usually want to fail as fast as possible (since those tests tend to be slow).
我认为这个想法是让你使用 JUnit 的Assert.assertXXX()
不同之处在于它verifyXXX
会在拆卸期间而不是立即失败,但我认为使用 Selenium 测试你通常希望尽可能快地失败(因为这些测试往往很慢)。
回答by Ripon Al Wasim
As SeleneseTestCase is deprecated, you can use SeleneseTestBase instead of SeleneseTestCase. The java code for this as below:
由于 SeleneseTestCase 已被弃用,您可以使用 SeleneseTestBase 而不是 SeleneseTestCase。这个的java代码如下:
import com.thoughtworks.selenium.SeleneseTestBase;
public class MySeleniumTest extends SeleneseTestBase{
@Test
public void aMethod(){
verifyTrue(boolean condition);
}
}
If you don't extends SeleneseTestBase class you can use an object as below:
如果您不扩展 SeleneseTestBase 类,您可以使用如下对象:
new SeleneseTestBase().verifyTrue(boolean condition);