Search code examples
javaseleniumcucumberend-to-endcucumber-serenity

Running multiple tests features with cucumber for java selenium serenity tests


I have following config to run the files in specific folder for java cucumber config (selenium tests).

 
package com.hero.selenium.test;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        monochrome = true,
        features = {"src/test/resources/features/"},
        glue = {"com.hero.selenium.test.stepdefinitions"}
)
public class MainRunner {
}

I know how to run just one file with

features = {"src/test/resources/features/AsiaUsersMutexTest.Feature"},

However, I want to run just the files starting with some string. Lets say files with prefix "AsiaUserTests". Something like the following

features = {"src/test/resources/features/AsiaUsers*.Feature"},

This results into java.nio.file.InvalidPathException: Illegal char <*>, so wondering if there is a way to do it as I couldn't find something like this in web.


Solution

  • I got this running by adding @Custom-Tag on features file that I want to run and modified the config as follows.

    package com.hero.selenium.test;

    import io.cucumber.junit.CucumberOptions;
    import net.serenitybdd.cucumber.CucumberWithSerenity;
    import org.junit.runner.RunWith;
    
    @RunWith(CucumberWithSerenity.class)
    @CucumberOptions(
            monochrome = true,
            features = {"src/test/resources/features/"},
            glue = {"com.hero.selenium.test.stepdefinitions"},
            tags= "@Custom-Tag"
    )
    public class MainRunner {
    }
    

    Thanks @lojza for the guidance!