Specify the feature file location in cucumber

后端 未结 5 1616
暖寄归人
暖寄归人 2021-01-05 09:49

I have created some cucumber test steps and a small Cucumber test case, which I run with JUnit like so:

@RunWith(Cucumber.class)

public class FuelCarTest {
         


        
相关标签:
5条回答
  • 2021-01-05 09:54

    I have placed all feature files in test/resources/features and added my feature file location with class path. Here is my cucumber run file.

    @RunWith(Cucumber.class)
    @CucumberOptions(
        monochrome = true,
        features = "classpath:features",
        plugin = {"pretty", "html:target/cucumber-reports",
        "json:target/cucumber.json"
                 }
    
    )
    public class MyTests 
    {
    
    }
    

    This will pick all feature files inside the folder features. If you want to have a subfolders you can add that too by just replacing the line as shown below.

    features = "classpath:features/DEV"

    If only one particular feature file, it should be like this

    features = "classpath:features/DEV/SmokeTests.feature"

    0 讨论(0)
  • 2021-01-05 10:08

    I found the solution,

    there is the @Cucumber.Options annotation, among setting the report output format and location, it also allows setting the location for the feature files.

    @Cucumber.Options(
        format = {
            "pretty",
            "html:target/cucumber-html-report",
            "json-pretty:target/cucumber- report.json"
        },
        features="features/"
    )
    
    0 讨论(0)
  • 2021-01-05 10:13

    You can use @CucumberOptions instead of @Cucumber.Options

    @RunWith(Cucumber.class)
    @CucumberOptions(
        format = "pretty",
        tags = {"~@Ignore"},
        features = "src/test/resources/com/"  //refer to Feature file
    )
    public class CucumberIT {  }
    
    0 讨论(0)
  • 2021-01-05 10:13

    here feature keyword for path of your feature file folder example: my feature files folder located in desktop

    so feature keyword value feature="C:\Users\sanjay\Desktop\features"

    @RunWith(Cucumber.class)
    @CucumberOptions(
    		features = "C:\\Users\\sanjay\\Desktop\\features"
    		,glue={"com.stepDefination"}
    		,monochrome = false,
    				
    				
    				format = {"pretty", "html:target/Destination"} 
    		
    		)
    public class TestRunner {
    
    }

    0 讨论(0)
  • 2021-01-05 10:14

    Here you can specify feature file from a folder, tag name and test outputs.

     @RunWith(Cucumber.class)
     @CucumberOptions(features="src/Login.feature",
        format = {"pretty", "html:target/report/",
        "json:target/report/cucu_json_report.json",
        "junit:target/report/cucumber_junit_report.xml",}
         tags ={"@ra1, @ra2"})
    
    0 讨论(0)
提交回复
热议问题