JUnit Test Suite for Selenium 2

2019-08-07 05:12发布

问题:

I have converted a Selenium Test Suite into JUnit from Selenium IDE, and trying to execute from eclipse. But there is an error in my script in

suite.addTestSuite(Open_Google_IE.class);
suite.addTestSuite(Open_Google_FireFox.class);

Error message: The method addTestSuite(Class) in the type TestSuite is not applicable for the arguments (Class).

Please advise what could be the reason. I have also verified Creating Test Suite in Webdriver and updated test suite but still throws that error.

JUnit TestSuite

import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses(value = {Open_Google_IE.class, Open_Google_FireFox.class})

public class OpenGoogle {

    public static Test suite() {
        TestSuite suite = new TestSuite();
        suite.addTestSuite(Open_Google_IE.class);
        suite.addTestSuite(Open_Google_FireFox.class);
        return suite;
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}

回答1:

As far as I can see, the code is OK.

addTestSuite() can only take classes that extend junit.framework.TestCase. Please make sure your classes extend that one, or find another way around...



回答2:

your class has to extend SeleniumTestBase

like this one :

public class CreateAccountTestCase extends SeleniumTestBase {