80% found this document useful (10 votes)
12K views2 pages

Cucumber 1st Handson

The document provides instructions for setting up a Cucumber test framework with Maven. It details steps to install necessary packages, create Java runner and step definition files in the correct project structure, and add a feature file. The final step is to run the tests with Maven and output the results to a file.

Uploaded by

h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
80% found this document useful (10 votes)
12K views2 pages

Cucumber 1st Handson

The document provides instructions for setting up a Cucumber test framework with Maven. It details steps to install necessary packages, create Java runner and step definition files in the correct project structure, and add a feature file. The final step is to run the tests with Maven and output the results to a file.

Uploaded by

h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Let's get the installations done, prior to creating tasks

apt-get install tree

Type ls to verify the folder.

cd maven-cucumber

and enter ls. You will find pom.xml and src folder.

To see the directory structure enter tree in your terminal.

go to below path using cd command.


src/test/java/com/play/bdd/runner/

Create a Java file inside the runner folder.

$ vi RunPlayTest.java
Once you have created java file, hit i to insert the code.

package com.play.bdd.runner;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
format = { "pretty", "html:target/cucumber" },
features = "classpath:cucumber/play.feature"
)
public class RunPlayTest {
}
Enter :wq to save the folder.

-------------------

cd ../steps/

$ vi PlaySteps.java
Hit i and copy this steps which you got in previous execution.

package com.play.bdd.steps;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

import static org.junit.Assert.assertEquals;


import static org.junit.Assert.assertNotNull;

public class PlaySteps {


@Given("^Play a learning platform$")
public void i_have_a_play() throws Throwable {
//System.out.println("This will print about play");

@When("^I want to learn$")


public void love_for_play() throws Throwable {
//System.out.println("This will print love for play");
}

@Then("^I open play to learn and earn$")


public void benefits_of_play() throws Throwable {
//System.out.println("This will print benefits of play");
}
}

------------
cd ../../../../../resources/cucumber

vi play.feature

paste the below code and save by using :wq


--------------------------

Feature: First cucumber HandsOn

This is my first cucumber hands on

Badly I want to crack it

Scenario: About my learning

Given Cucumber is really easy to learn

When I have to pass this hand on

Then This will test my cucumber skills

---------------------------

cd /root/maven-cucumber/

mvn clean test | tee output.txt

You might also like