追求代码质量: 使用 Selenium 和 TestNG 进行编程式测试
2009-11-19 00:00:00 来源:WEB开发网结果产生一个灵活的文本类,它将检验两种场景:一种是良好的场景,而另一种是没有提供定义的边界用例,如清单 7 所示:
清单 7. 使用 TestNG 进行全部的处理public class CreateWidgetUATest {
private Selenium driver;
@Parameters({"selen-svr-addr","brwsr-path","aut-addr"})
@BeforeClass
private void init(String selenSrvrAddr, String bpath,
String appPath) throws Exception {
driver = new DefaultSelenium(selenSrvrAddr,
SeleniumServer.getDefaultPort(), bpath, appPath);
driver.start();
}
@Parameters({"aut-addr"})
@Test
public void verifyCreate(String appPath) throws Exception {
driver.open(appPath + "/CreateWidget.html");
driver.type("widget", "book-01");
driver.select("type", "book");
driver.type("definition", "book widget type book");
driver.click("submit");
driver.waitForPageToLoad("10000");
assertEquals(driver.getText("success"),
"The widget book-01 was successfully created.",
"test didn't return expected message");
}
@Parameters({"aut-addr"})
@Test
public void verifyCreationError(String appPath) throws Exception {
driver.open(appPath + "/CreateWidget.html");
driver.type("widget", "book-02");
driver.select("type", "book");
//definition explicitly set to blank
driver.type("definition", "");
driver.click("submit");
driver.waitForPageToLoad("10000");
assertEquals(driver.getText("failure"),
"There was an error in creating the widget.",
"test didn't return expected message");
}
@AfterClass
private void stop() throws Exception {
driver.stop();
}
}
更多精彩
赞助商链接