Santhosh Siddappa
Santhosh Siddappa

Reputation: 718

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

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

Upvotes: 0

Views: 3933

Answers (2)

cralfaro
cralfaro

Reputation: 5948

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;
    }

}

Upvotes: 1

featuredpeow
featuredpeow

Reputation: 2201

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.

Upvotes: 4

Related Questions