Enable Cucumber in Java project
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.0.11</version>
<type>pom</type>
</dependency>
WARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead.
1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^User details$")
public void user_details() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^UI submits the User data$")
public void ui_submits_the_User_data() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^return Message user is authenticated$")
public void return_Message_user_is_authenticated() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Undefined step: Given User details
Undefined step: When UI submits the User data
Undefined step: Then return Message user is authenticated
1 scenario (0 passed)
3 steps (0 passed)
Process finished with exit code 0
We have not implemented steps mentioned in feature file so thats why it is giving this error.
Will create TestSuit.java dn paste it.
WARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead.
Skipped step
Skipped step
Skipped step
1 scenario (0 passed)
3 steps (0 passed)
1 Scenarios (1 pending)
3 Steps (2 skipped, 1 pending)
0m0.742s
cucumber.api.PendingException: TODO: implement me
at features.TestSuit.user_details(TestSuit.java:13)
1 Scenarios (1 passed)
3 Steps (3 passed)
0m0.559s
1 scenario (1 passed)
3 steps (3 passed)
Process finished with exit code 0
Now in this steps all the steps are passed.
We are done with cucumber integration.
1) Enable using maven
Create Maven project and Add below dependency in pom.xml<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.0.11</version>
<type>pom</type>
</dependency>
2) Download and install cucumber plugin for eclipse
http://marketplace.eclipse.org/content/cucumber-jvm-eclipse-plugin3) Create feature file in your project
To create a feature file
- In the Project tool window, right-click a directory, where feature files should be created.
- On the context menu of the target directory, choose , and in the New File dialog box, type
<name>.feature.
4) Write Steps in feature file
Feature: Login
@smoke
Scenario: Login Functionality
Given User details
When UI submits the User data
Then return Message user is authenticated
5) We have cucumber plugin installed in eclipse IDE so right click on feature file and run it.
It will show you below output on consoleWARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead.
1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^User details$")
public void user_details() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^UI submits the User data$")
public void ui_submits_the_User_data() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^return Message user is authenticated$")
public void return_Message_user_is_authenticated() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Undefined step: Given User details
Undefined step: When UI submits the User data
Undefined step: Then return Message user is authenticated
1 scenario (0 passed)
3 steps (0 passed)
Process finished with exit code 0
We have not implemented steps mentioned in feature file so thats why it is giving this error.
Step 6) Copy methods present below "You can implement missing steps with the snippets below:" string in console.
Create new class in same package and paste them in that.Will create TestSuit.java dn paste it.
package features;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class TestSuit {
@Given("^User details$")
public void user_details() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^UI submits the User data$")
public void ui_submits_the_User_data() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^return Message user is authenticated$")
public void return_Message_user_is_authenticated() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}
Step 7) Again right click in feature file and run it .
Now it will give below error because we have not implemented above methods and they are still havingthrow new PendingException();in theire methods
WARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead.
Skipped step
Skipped step
Skipped step
1 scenario (0 passed)
3 steps (0 passed)
1 Scenarios (1 pending)
3 Steps (2 skipped, 1 pending)
0m0.742s
cucumber.api.PendingException: TODO: implement me
at features.TestSuit.user_details(TestSuit.java:13)
Step 8) Either implement your logic in these methods or for just testing purpose remove these exception from methods.
now code will look likepackage features;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class TestSuit {
@Given("^User details$")
public void user_details() throws Throwable {
// Write code here that turns the phrase above into concrete actions
}
@When("^UI submits the User data$")
public void ui_submits_the_User_data() throws Throwable {
// Write code here that turns the phrase above into concrete actions
}
@Then("^return Message user is authenticated$")
public void return_Message_user_is_authenticated() throws Throwable {
// Write code here that turns the phrase above into concrete actions
}
}
Step 9) Run feature file again
you will get below output1 Scenarios (1 passed)
3 Steps (3 passed)
0m0.559s
1 scenario (1 passed)
3 steps (3 passed)
Process finished with exit code 0
Now in this steps all the steps are passed.
We are done with cucumber integration.
No comments:
Post a Comment