How to run a single cucumber file


633
633 points
how to run a single cucumber file
how to run a single cucumber file

How to run a single cucumber file

When you develop you cucumber tests you do need to run single cucumber file. Here is how to run a single cucumber file.

Run single cucumber file in ruby (macOS)
cucumber features/feature_name.feature
Run single cucumber file in ruby (Linux)
bundle exec cucumber features/feature_name.feature

If you have a pipeline job you might want to run a single cucumber file in jenkins in headless mode you can configure your pipeline to run a single file rather than running parallel of all tests.

You can simply create a method that calls the run tests method below which determines which set of tests to run based on the build variables.

node(){
   timestamps {
        stage 'Running tests'
         try{
             if ( !env.FEATURE && !env.CUCUMBER_TAG ) {
                              runTests();
                  } else if (env.FEATURE && env.CUCUMBER_TAG) {
                              runfeaturefile();
                              runTags();
                          }
                      else if (env.FEATURE && !env.CUCUMBER_TAG) {
                              runfeaturefile();
                          }
                      else if (!env.FEATURE && env.CUCUMBER_TAG) {
                              runTags();
                   }
      }catch(err) {
                echo "Build failed at ; stage('Running tests')"
                echo err.getMessage();

               }
        }
}

Where run featurefile();:

// run feature/features that are provided into the build
def runfeaturefile(){
    echo "Running feature file"
    def features = env.FEATURE
    List<String> items = Arrays.asList(features.split("\\s*,\\s*"));
    try{
        for (int i = 0; i < items.size(); i++) {
          runner.runfeature('testfeature${i}',items[i]);
        }
    } finally {
    cleanup.dockerCleanup("docker.endpoint/ruby-autotest:${env.BUILD_NUMBER}");
    }
    currentBuild.description="Tested ${env.AUTO_BRANCH}"
}

Happy testing!

 


Like it? Share with your friends!

633
633 points
Test engineer

0 Comments

Your email address will not be published. Required fields are marked *

four × 4 =