Running the tests or features from the command line or terminal without using the IDE or GUI.
Why
No dependency on IDE or GUI
Useful in integrations with other processes like CI/CD or deployment or release process. It will be easier and faster with command-line execution. It also consumes less memory.
When:
Whenever using CI tools like Jenkins
Whenever you need any batch or scheduled execution
Open command line
Navigate to project directory (cd "path")
mvn test
By default mvn test runs the files with naming syntax as below:
**/*Test*.java
**/Test*.java
**/OrderTest.java
Hence keep this naming convention only for the cucumber runner file. It will be run when execute the command mvn test from the command line.
CucumberOptions from command line:
1. Running a feature
mvn test -Dcucumber.options="src\test\resources\features\demo.feature"
2. Running a scenario in a feature file
mvn test -Dcucumber.options="src\test\resources\features\demo.feature:6"
3. Running with tags:
mvn test -Dcucumber.options="--tags @regression"
Or
mvn test -Dcucumber.options="-t @regression"
4. Reports
mvn test -Dcucumber.options="--plugin html:target/HtmlReport"
Or
mvn test -Dcucumber.options="-p html:target/HtmlReport"
5. Multiple options
mvn test -Dcucumber.options="src\test\resources\features\demo.feature:6" -Dcucumber.options="-p html:target/HtmlReports"