Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SeleneseTestCase is deprecated - how to call verify* methods?

Tags:

java

selenium

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"));
    .....
like image 787
Mason Avatar asked Feb 23 '11 17:02

Mason


2 Answers

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

like image 106
CarlosZ Avatar answered Nov 10 '22 17:11

CarlosZ


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);
like image 41
Ripon Al Wasim Avatar answered Nov 10 '22 16:11

Ripon Al Wasim