3

I have jbehave integrated with Selenium. I am running my tests through command line as below C:\eclipse_workspace\MySeleniumTests>mvn clean test -Dwebdriver.firefox.bin="C:\Program Files\Mozilla\Firefox\firefox.exe"

I have used jbehave-maven-plugin. Maven picks up all the Embedder impl (JunitStories in my case) from the source directory and execute them one by one. Configuration for that is <include>**/*Stories.java</include> in pom.xml

It then looks for relevant .story files in the specified dir and executes them. Say, I have two story files one.story and two.story, both of them are executed.

Over a time, number of story files are going to increase I only want to execute specific story files should there be a way to do this? I am thinking to pass specific story file names as run time parameters but don’t know what is required to make that happen.

4

2 回答 2

4

我得到它使用下面的代码

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;
    }
于 2013-09-23T10:28:12.453 回答
1

尝试以下操作:

mvn clean test -Dwebdriver.firefox.bin="C:\Program Files\Mozilla\Firefox\firefox.exe" -Djbehave.story.name=<story filename without extension (wildcards are supported)>

您还应该使用自定义测试套件实现:

public abstract class JBehaveTestSuite extends ThucydidesJUnitStories {

    private static final String STORY_NAME_PATTERN = "**/${jbehave.story.name:*}.story";

    public JBehaveTestSuite() {
        findStoriesCalled(storyNamesFromEnvironmentVariable());
    }

    @Override
    public void run() throws Throwable {
        super.run();
    }

    private String storyNamesFromEnvironmentVariable() {
        return SystemPropertyUtils.resolvePlaceholders(STORY_NAME_PATTERN);
    }
}
于 2013-09-06T17:16:22.500 回答