How to run cucumber file from command line
Asked Answered
B

2

12

I have cucumber feature file located at below location on my local:

C:\ProjectWork\Workspace\Cucumber\DIT_Cucumber\src\cucumber\featureOne.feature

and Junit jar at below location:

C:\DurgeshProjectWork\Workspace\JarFiles\junit-4.11.jar

When I have tried several commands like below to execute the feature file from command prompt however all the time getting same error as

Could not fine class

Below are the commands which I used: Command 1:

C:\>java -cp C:\ProjectWork\Workspace\JarFiles\junit-4.11.jar org.junit.runner.JUnitCore C:\DurgeshProjectWork\Workspace\Cucumbe
r\DIT_Cucumber\bin\cucumber\featureOne.feature

Command 2:

C:\ProjectWork\Workspace\Cucumber\DIT_Cucumber\src\cucumber>java -cp C:\ProjectWork\Workspace\JarFiles\junit-4.11.jar org
.junit.runner.JUnitCore featureOne.feature

Could you please help me to run this feature file from command line. Thanks in advance.

Burglarious answered 2/6, 2015 at 3:43 Comment(1)
HI Team, Any suggestions??????? I haven't received any reply on it yet. thanks!Burglarious
J
15

JUnit Approach

If using JUnit, you can run the test the same way you would run a JUnit test on the command line:

java -cp <classpath> org.junit.runner.JUnitCore com.example.test.RunCukesTest

where RunCukesTest is the unit test that sets all the cucumber options, e.g.:

package com.example.test;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "json:target/report.json")
public class RunCukesTest {
}

Cucumber-jvm Approach

You can also use cucumber-jvm on the command line:

java -cp <classpath> cucumber.api.cli.Main \
   --glue com.example.test \
   --plugin pretty path/to/features

Maven

The challenge in both previous cases is to build the classpath and make sure all the dependencies are properly loaded, including your own classes and the feature files. An easier solution would be to use for example Maven to define all the deps; running the tests is then as simple as:

mvn verify
Jesusitajet answered 3/6, 2015 at 13:3 Comment(2)
Thanks for detailed info, can you please clarify how to do with gradle as well ? gradle is replacing maven and it will be nice to include it as well in the answer. Thanks, VikramHeterolecithal
Hi, what about using cucumber.options from command line without maven? Do you know how to use it?Estray
F
0

Cucumber with Java:

Run Feature: java -cp "jars/*" cucumber.api.cli.Main -p pretty features

compile Step Definition file: javac -cp "jars/*" step_definition/StepDef.java

Run Scenario: java -cp "jars/*;." cucumber.api.cli.Main -p pretty -g step_definition features

Fillander answered 25/7, 2016 at 11:9 Comment(2)
Here features is directory of feature files and step_definition is a directory of Step Definition files.Fillander
how to specify multiple --tags option with multiple tags?Haith

© 2022 - 2024 — McMap. All rights reserved.