【发布时间】:2015-12-07 08:24:23
【问题描述】:
我刚刚创建了打开谷歌的功能文件,并在搜索引擎中输入了一些值并验证了搜索结果。此外,我创建了一个包含给定、何时和然后注释的步骤类文件。现在,我想创建一个测试运行器,用于根据故事文件驱动步骤类文件。但就我而言,我想使用 TestNG 而不是 Junit 框架。我在谷歌上搜索了几个站点,都解释了如何集成 Jbehave+Junit。但是,到目前为止,我还没有找到任何 Jbehave+TestNG 组合的站点。由于我自己在尝试,因此我只需要对此有所了解。谁能给我一个示例代码,帮助我更好地理解。
请查找示例故事:
scenario: Check the google search engine
Given : Open the google home page www.google.com
When : Enter test automation in search box
Then : Proper result should be displayed in results page
步骤类文件:
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchEngine {
public static WebDriver driver;
@Given("Open the google home page $url")
public static void openUrl(String url) throws Exception {
try {
driver = new FirefoxDriver();
driver.get(url);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@When("Enter $searchKeyword in search box")
public static void searchKeyword(String searchKeyword) throws Exception {
try {
driver.findElement(By.xpath(".//*[@id='gs_htif0']")).sendKeys(searchKeyword);
driver.findElement(By.xpath(".//*[@id='tsf']/center/input[1]")).click();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Then("Proper result should be displayed in results page")
public static void result() throws Exception {
try {
driver.quit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
然后我需要开发用于驱动故事文件的testrunner。
有人可以帮我使用 TestNG 框架创建一个测试运行器类文件吗?
【问题讨论】:
标签: java selenium-webdriver testng jbehave