在实践中使用Selenium 2.0 WebDriver
发布时间:2020-05-24 10:13:35 所属栏目:Java 来源:互联网
导读:我想在JUnit中编写Selenium测试用例并在多个浏览器中测试我的项目,我想利用所有Selenium驱动程序实现相同接口的事实. 每个测试用例应如下所示: package fm;import org.openqa.selenium.WebElement;import org.openqa.selenium.By;import org.openqa.selenium
|
我想在JUnit中编写Selenium测试用例并在多个浏览器中测试我的项目,我想利用所有Selenium驱动程序实现相同接口的事实. 每个测试用例应如下所示: 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) {
//...
}
}
传递的WebDriver实现应该集中控制.我可能需要覆盖一些JUnit行为,我希望它是可能的. 我想这样做是为了避免两件事: >代码重复:如果每个测试用例都会在@Before中初始化所有经过测试的浏览器,那么测试套件会有很多重复的代码难以维护. 有人知道我应该怎么做?谢谢. 解决方法在Selenium项目中,我们使用 http://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/AbstractDriverTestCase.java注入我们需要的东西,然后我们的构建调用浏览器,我们在其中运行测试.看看我们的代码库,以获得一些灵感! (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
