简体   繁体   中英

SeleneseTestCase is deprecated - how to call verify* methods?

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.

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?

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"));
    .....

我认为你的想法是使用JUnit的Assert.assertXXX() ,不同之处在于verifyXXX会在拆卸过程中失败而不是立即失败但我认为使用Selenium测试你通常想尽快失败(因为那些测试往往很慢) )。

As SeleneseTestCase is deprecated, you can use SeleneseTestBase instead of SeleneseTestCase. The java code for this as below:

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:

new SeleneseTestBase().verifyTrue(boolean condition);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM