Java 如何在serenity BDD Jbehave中按特定顺序执行故事文件

Java 如何在serenity BDD Jbehave中按特定顺序执行故事文件,java,selenium-webdriver,jbehave,serenity-bdd,thucydides,Java,Selenium Webdriver,Jbehave,Serenity Bdd,Thucydides,我在stories文件夹中有几个jbehave故事文件。每当我执行脚本时,它都会按字母顺序执行 例: 当前执行 故事 bbb.故事 故事 我要执行死刑 故事 bbb.故事 跳过这个故事 是否有一种方法可以按特定顺序运行特定的故事。 在Serenity BDD+Jbehave中,您可以使用来标记故事/场景。如果您只想运行故事/场景的子集或跳过其中的一些场景,这将非常有用。 例如: 然后,您可以使用和包含/排除带有特定标记的场景 您可以更改故事文件名,以便它们的字典顺序与您希望它们执行的顺序相匹配:

我在stories文件夹中有几个jbehave故事文件。每当我执行脚本时,它都会按字母顺序执行

例: 当前执行

故事

bbb.故事

故事

我要执行死刑

故事

bbb.故事

跳过这个故事

是否有一种方法可以按特定顺序运行特定的故事。 在Serenity BDD+Jbehave中,您可以使用来标记故事/场景。如果您只想运行故事/场景的子集或跳过其中的一些场景,这将非常有用。 例如:

然后,您可以使用和包含/排除带有特定标记的场景

您可以更改故事文件名,以便它们的字典顺序与您希望它们执行的顺序相匹配:

1_aaa.story  
2_bbb.story
3_ccc.story
或创建单独的文件夹:

a/aaa.story
a/bbb.story
c/ccc.story
当您需要在另一个故事之前执行某个故事时,有一个更好的解决方案,子句:

这将首先执行aaa.story,然后执行此story。您可以在
GivenStories

中指定多个故事,您可以使用它们来标记故事/场景。如果您只想运行故事/场景的子集或跳过其中的一些场景,这将非常有用。 例如:

然后,您可以使用和包含/排除带有特定标记的场景

您可以更改故事文件名,以便它们的字典顺序与您希望它们执行的顺序相匹配:

1_aaa.story  
2_bbb.story
3_ccc.story
或创建单独的文件夹:

a/aaa.story
a/bbb.story
c/ccc.story
当您需要在另一个故事之前执行某个故事时,有一个更好的解决方案,子句:


这将首先执行aaa.story,然后执行此story。您可以在
GivenStories

中指定几个故事,我有一些类似的场景,我所做的是创建一个自定义ThucydiesJunitstories,在我的情况下,我只需要加载每个故事的步骤以避免冲突,但在您的情况下,您可以向故事列表添加任何类型的排序。范例

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

}
公共类CustomThucydidesJUnitTories扩展了ThucydidesJUnitTories{
Logger Logger=LoggerFactory.getLogger(CustomThucydidesJUnitStories.class);
私有配置;
私有列表格式=Arrays.asList(控制台、统计信息、HTML);
@试验
@凌驾
public void run()抛出可丢弃的{
列出故事路径=故事路径();
info(“要运行的总故事数为{}”,storypath.size());
//在这里,您可以根据需要对故事路径进行排序
用于(字符串故事路径:故事路径){
Embedder Embedder=configuredEmbedder();
useConfiguration(configuration());
String storyName=storyPath.substring(storyPath.lastIndexOf(“/”)+1,storyPath.indexOf(“.story”);
info(“正在运行的故事{}”,故事名);
embedder.useStepsFactory(ThucydidesStepFactory.withStepsFromPackage(getRootPackage()+“+”+storyName,configuration())和ClassLoader(getClassLoader());
使用EmbedderControls(ignoreFailsEmbedderControls());
embedder.runstoriesapaths(list.newArrayList(storyPath));
}
}
公共EmbedderControls ignoreFailsEmbedderControls(){
返回新的EmbedderControls();
}
@凌驾
公共配置(){
if(配置==null){
net.thucydides.core.webdriver.Configuration thucydidesConfiguration=getSystemConfiguration();
configuration=ThucydidesJBehave.defaultConfiguration(thucydidesConfiguration,formats,this);
}
返回配置;
}
}

我有一些类似的场景,我所做的是创建一个自定义ThucydidesJUnitTories,在我的情况下,我只需要加载每个故事的步骤,以避免冲突,但在您的情况下,您可以将任何种类的排序添加到您的故事列表中。范例

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

}
公共类CustomThucydidesJUnitTories扩展了ThucydidesJUnitTories{
Logger Logger=LoggerFactory.getLogger(CustomThucydidesJUnitStories.class);
私有配置;
私有列表格式=Arrays.asList(控制台、统计信息、HTML);
@试验
@凌驾
public void run()抛出可丢弃的{
列出故事路径=故事路径();
info(“要运行的总故事数为{}”,storypath.size());
//在这里,您可以根据需要对故事路径进行排序
用于(字符串故事路径:故事路径){
Embedder Embedder=configuredEmbedder();
useConfiguration(configuration());
String storyName=storyPath.substring(storyPath.lastIndexOf(“/”)+1,storyPath.indexOf(“.story”);
info(“正在运行的故事{}”,故事名);
embedder.useStepsFactory(ThucydidesStepFactory.withStepsFromPackage(getRootPackage()+“+”+storyName,configuration())和ClassLoader(getClassLoader());
使用EmbedderControls(ignoreFailsEmbedderControls());
embedder.runstoriesapaths(list.newArrayList(storyPath));
}
}
公共EmbedderControls ignoreFailsEmbedderControls(){
返回新的EmbedderControls();
}
@凌驾
公共配置(){
if(配置==null){
net.thucydides.core.webdriver.Configuration thucydidesConfiguration=getSystemConfiguration();
configuration=ThucydidesJBehave.defaultConfiguration(thucydidesConfiguration,formats,this);
}
返回配置;
}
}