【问题标题】:How do i execute story files in specific order in serenity BDD Jbehave我如何在 Serenity BDD Jbehave 中按特定顺序执行故事文件
【发布时间】:2016-08-29 13:41:24
【问题描述】:

我的故事文件夹中的 jbehave 故事文件很少。每当我执行它按字母顺序执行的脚本时。

例如: 当前执行

aaa. 故事

bbb.故事

ccc.故事

我希望执行是

ccc.故事

bbb.故事

跳过 aaa.story

有没有办法以特定的顺序运行特定的故事。 在 Serenity BDD + Jbehave 中

【问题讨论】:

    标签: java selenium-webdriver jbehave serenity-bdd thucydides


    【解决方案1】:

    您可以使用Meta: 标记故事/场景。如果您只想运行故事/场景的子集或跳过其中一些,这很有用。 示例:

    Meta: @sometag
    
    Scenario: some scenario
    Given something 
    

    然后你可以使用meta filteringstory mapping来包含/排除带有特定标签的场景。

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

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

    或创建单独的文件夹:

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

    如果您需要在另一个故事之前执行一些故事,有更好的解决方案,GivenStories: 子句:

    GivenStories: aaa.story
    
    Scenario: requires aaa to run
    Given something
    

    这将首先执行 aaa.story 然后这个故事。您可以在GivenStories 中指定多个故事。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多