How do i execute story files in specific order in serenity BDD Jbehave

隐身守侯 提交于 2019-12-12 02:09:58

问题


I Have few jbehave story files in stories folder. whenever i execute the scripts it takes in alphabetical order.

ex: current execution

aaa.story

bbb.story

ccc.story

i want the execution to be

ccc.story

bbb.story

and skip aaa.story

is there a way to run specific stories in specific order. in Serenity BDD + Jbehave


回答1:


You can use Meta: to tag stories/scenarios. This is useful if you want to run just subset of stories/scenarios or skip some of them. Example:

Meta: @sometag

Scenario: some scenario
Given something 

Then you can use meta filtering and story mapping to include/exclude scenarios marked with certain tags.

You can change story file names so their lexicographical order will match order you want them to execute:

1_aaa.story  
2_bbb.story
3_ccc.story

or create separate folders:

a/aaa.story
a/bbb.story
c/ccc.story

There is more nice solution in case when you need some story to execute before another one, GivenStories: clause:

GivenStories: aaa.story

Scenario: requires aaa to run
Given something

This will first execute aaa.story then this story. You can specify several stories in GivenStories.




回答2:


I have some similar scenario and what i did was create a custom ThucydidesJUnitStories, in my case i needed load only the steps for each story to avoid conflicts but in your case you could add any kind of sort to your stories list. Example

public class CustomThucydidesJUnitStories extends ThucydidesJUnitStories   {

    Logger logger = LoggerFactory.getLogger(CustomThucydidesJUnitStories.class);

    private Configuration configuration;
    private List<Format> formats = Arrays.asList(CONSOLE, STATS, HTML);

    @Test
    @Override
    public void run() throws Throwable {
        List<String> storyPaths = storyPaths();
    logger.info("Total stories to run are {}", storyPaths.size());
        //HERE YOU CAN SORT THE storyPaths as you wish 
        for(String storyPath : storyPaths) {
            Embedder embedder = configuredEmbedder();
            embedder.useConfiguration(configuration());
            String storyName =   storyPath.substring(storyPath.lastIndexOf("/") + 1,   storyPath.indexOf(".story"));
            logger.info("Running story {}", storyName);
           embedder.useStepsFactory(ThucydidesStepFactory.withStepsFromPackage(getRootPackage() + "." + storyName,   configuration()).andClassLoader(getClassLoader()));
            embedder.useEmbedderControls(ignoreFailsEmbedderControls());
            embedder.runStoriesAsPaths(Lists.newArrayList(storyPath));
        }
    }

    public EmbedderControls ignoreFailsEmbedderControls() {
        return new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
    }

    @Override
    public Configuration configuration() {
        if (configuration == null) {
             net.thucydides.core.webdriver.Configuration thucydidesConfiguration = getSystemConfiguration();
             configuration = ThucydidesJBehave.defaultConfiguration(thucydidesConfiguration, formats, this);
        }
        return configuration;
    }

}


来源:https://stackoverflow.com/questions/39207774/how-do-i-execute-story-files-in-specific-order-in-serenity-bdd-jbehave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!