我已将 jbehave 与 Selenium 集成。我正在通过命令行运行测试,如下所示
C:\eclipse_workspace\MySeleniumTests>mvn clean test -Dwebdriver.firefox.bin="C:\Program Files\Mozilla\Firefox\firefox.exe"
我使用过 jbehave-maven-plugin。 Maven 从源目录中获取所有的 Embedder impl(在我的例子中是 JunitStories)并一个一个地执行它们。配置为 <include>**/*Stories.java</include>
在 pom.xml 中
然后它会在指定的 dir
中查找相关的 .story 文件并处决他们。比如说,我有两个故事文件 one.story 和 two.story,它们都被执行了。
随着时间的推移,故事文件的数量将会增加我只想执行特定的故事文件,应该有办法做到这一点吗?我正在考虑将特定的故事文件名作为运行时参数传递,但不知道实现这一点需要什么。
最佳答案
我用下面的代码让它工作
mvn clean test -Dwebdriver.firefox.bin="C:\Program Files\Mozilla\Firefox\firefox.exe" -Dstory=myStory.story
重写嵌入类中的 storyPaths() 方法,如下所示。
public class MyTestStories extends JUnitStories /* InjectableEmbedder */{
@Override
protected List<String> storyPaths() {
List<String> storiesToRun = new ArrayList<String>();
String storyProperty = System.getProperty("story");
if (storyProperty == null || storyProperty.isEmpty()) {
throw new RuntimeException("Please specify which stories to run");
}
String[] storyNames = storyProperty.split(",");
StoryFinder sf = new StoryFinder();
URL baseUrl = CodeLocations.codeLocationFromClass(this.getClass());
for (String storyName : storyNames) {
storiesToRun.addAll(sf.findPaths(baseUrl, storyName, ""));
}
return storiesToRun;
}
关于selenium - jbehave 只运行特定的故事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640539/