Using selenium 2.0 webdriver in practice

I want to write selenium test cases in JUnit and test my project in multiple browsers. I want to take advantage of the fact that all selenium drivers implement the same interface

Each test case shall be as follows:

package fm;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import static org.junit.Assert.*;

public class HomepageTest {

    @Test
    public void testTitle(WebDriver driver) {
        driver.get("http://localhost/");
        assertEquals("Foo",driver.getTitle());
    }

    @Test
    public void testSearchForm(WebDriver driver) {
        //...
    }

}

The webdriver implementation passed should be controlled centrally I may need to override some JUnit behavior, and I hope it's possible

I think this is to avoid two things:

>Code duplication: if each test case initializes all tested browsers in @ before, the test suite will have a lot of duplicate code that is difficult to maintain. > Speed of test suite: if I centrally control the order and implement it through webdriver, I can easily set up and open, such as Firefox, run all test cases in it, close it and open the next browser If each test case can open and close the browser by itself, each test run will increase a lot of time

Does anyone know what I should do? thank you.

Solution

In selenium project, we use http://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/AbstractDriverTestCase.java Inject what we need, and then our build calls the browser where we run the tests

Check out our code base for some inspiration!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>