Saturday, February 1, 2020

How to Create Maven Project with Cucumber


1. Create Maven Project First.
2. Open pom.xml file

We need below Properties and Dependencies for Cucumber Project :
<properties>
<cucumber.version>4.2.0</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
       </dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

Then Our Feature File would be Inside Resources and Code would be Inside Test
pom.xml & src folder execute it self .

If we want to see feature file data automatically would be there then need to install cucumber Eclipse plugin, this plugin is for identifying Jerkin syntax
Create features Package Inside src/Test/resources by right clicking on it with Name feature then Create one file inside feature Package by right click on feature Package ->New->Others-> Search file in wizards, then Select File from General -> Click next-> Name file as MyFirstFeature.feature -> Finish.

Lot of things Automatically came in inside feature file because we have installed that plugin.
If we have not installed

if we have not installed that plugin then simple blank file would be created. still we execute it from maven

Single feature file can have multiple Scenarios

Define definition of tag with team:
@smoke @reg @module_specific

We can execute feature file via cucumber command line. but we want to run it from maven runner file or from pom.xlm file. we will create runner file in src/test/java
We want to customize things use @tag cucumber options, If feature file in a specific folder its step definition is also present in the source folder

We package inside src/test/java name it cucumbertestsample.runner
create Class inside it with name RunnerTest

surefire will automatically pick it when there is name Test inside class name.

package cucumbertestsample.runner;

import org.junit.runner.RunWith;

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


@RunWith(Cucumber.class)
@CucumberOptions(
features="classpath:feature",
glue="stepdefs",
plugin= {"pretty",
"html:test-output/cucumberreport"
}
)
public class RunnerTest {

}










Create it & execute it by go to using runnerTest->Run As-> Junit Test

It say I  have tried executing all but I couldn't find any stepdefs file

Scenario Outline: Is use for data driven feature
execute for each set of step
see this for it:
 @tag2
  Scenario Outline: Title of your scenario outline
    Given I want to write a step with <name>
    When I check for the <value> in step
    Then I verify the <status> in step

    Examples:
      | name  | value | status  |
      | name1 |     5 | success |
      | name2 |     7 | Fail    |

Now will see it from cmd line:

No comments:

Post a Comment