Cucumber is not providing the method signatures for steps in the feature file - cucumber

I'm trying to fill out the fields on this demo site: http://newtours.demoaut.com/mercuryregister.php
This is my feature file:
Feature: Testing Mercury Tours' register page
Background:
Given the user has launched their browser
And the browser is on Mercury Tour's register page
Scenario Outline: Testing Mercury Tours' registration page via positive testing
When the user enters the "<First Name>"
And enters the "<Last Name>"
And enters the "<Phone>"
And enters the "<Email>"
And enters the "<Address>"
And enters the "<City>"
And enters the "<State>"
And enters the "<Postal Code>"
And selects the "<Country>"
And enters the "<User Name>"
And enters the "<Password>"
And enters the "<Confirm Password>"
Examples:
| First Name | Last Name | Phone | Email | Address | City | State | Postal Code | Country | User Name | Password | Confirm Password |
| Bob | Mayer | 1-877-393-4448 | BobM#example.com | 123 Victory Lane | Beverly Hills | CA | 90210 | United States | BobM | 123password | 123password |
When I run this feature file, Cucumber gives me the method signatures for the first two steps (first name & last name) and the Select draw down menu (fpr country) but not the rest:
#When("^the user enters the \"([^\"]*)\"$")
public void the_user_enters_the(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^enters the \"([^\"]*)\"$")
public void enters_the(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^selects the \"([^\"]*)\"$")
public void selects_the(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
How do I implement methods to fill other text fields like phone #, email, and address?

The other "missing" steps match the same pattern - ^enters the \"([^\"]*)\"$ which is the second one. If u want cucumber to emit step definition method signatures for each step consider making them unique. Change And enters the "<Phone>" to something like And enters phone details - "<Phone>".

Related

Cucumber - Scenario outline - When i use scenario out line for data parameterization , after run it throws an error and all steps are skipped

Below is the Cucumber Scenario in which steps 1,2,4,5,6 are working fine as it picks from other feature
file but then 3 and 7 step is giving an problem.
#Api
Scenario Outline: Getting Primary category count from Solr
Given User should have the base url for search vehicle
When User passes items per page as "20"
And User passes facet region as "US" and primarycategory type as "<Primary Category>"
And User fetches records with "/api/vehicles" endpoint
Then User should get status code "200" in response
And User should get 20 vehicles records in the response
Then User should get "<Primary Category>" count as "<Category Count>" in the response
Examples:
| Primary Category | Category Count |
| truck | 2125 |
| Tractor | 2366 |
| Trailer | 530 |
| Specialized | 0 |
| Reclassified | 0 |
Below is my code
#And("^User passes facet region as \"([^\"]*)\" and primarycategory type as \"([^\"]*)\" $")
public void user_passes_facet_region_as_and_primarycategory_type_as(String region, String primary_category) {
httpRequest.queryParam("facets", "r="+region+";g="+primary_category).urlEncodingEnabled(true);
}
#Then("User should get \"([^\"]*)\" count as \"([^\"]*)\" in the response$")
public void user_should_get_primary_category_count_as_in_the_response(int int1) {
int cat_count = response.jsonPath().get("Data.Count");
Assert.assertEquals(cat_count,int1);
}
After run i am getting the below error on console
#Api
Scenario Outline: Getting Primary category count from Solr # featurefile/PrimaryCategoryCount_From_Solr_API.feature:16
Given User should have the base url for search vehicle # FacetsSearchAPISteps.user_should_have_the_base_url_for_search_vehicle()
When User passes items per page as "20" # FacetsSearchAPISteps.user_passes_items_per_page_as(String)
And User passes facet region as "US" and primarycategory type as "truck" # null
And User fectches records with "/api/vehicles" endpoint # FacetsSearchAPISteps.user_fectches_records_with_endpoint(String)
Then User should get status code "200" in response # FacetsSearchAPISteps.i_should_get_status_code_in_response(String)
And User should get 20 vehicles records in the response # FacetsSearchAPISteps.user_should_get_vehicles_records_in_the_response(int)
Then User should get "truck" count as "2125" in the response # PrimaryCategoryCount_From_Solr_API_Steps.user_should_get_primary_category_count_as_in_the_response(int)
I dont know where is the issue can somebody help me.

Fetching all cucumber scenarios that have a particular tag

How can I fetch a list of all the scenarios that have a particular tag. For example
get all scenarios that have #checkout tag.
Lets assume you have 15-20 Scenarios/Scenarios Outline tagged with #checkout.
#checkout
Scenario Outline: Validation of UseCase Guest User Order Placement flow from Search
Given User is on Brand Home Page <Site>
And User searches for a styleId and makes product selection on the basis of given color and size
| Style_ID | Product_Size | Product_Color |
| TestData1 | TestData1 | TestData1 |
| TestData2 | TestData2 | TestData2 |
Then Clicking on Cart icon shall take user to Shopping Bag
Please follow this way to fetch name of scenarios.
File name Hook.java
#Before
public void setUpScenario(Scenario scenario){
String scenarioName = scenario.getName();
//Either you can write down name of the scenario under a file system like excel or implement in the way you want
}
Please lets know if you find it meaningful and it solved your problem.
Dry run to the rescue.
Dry run gives you a way to quickly scan your features without actually running them.
Try the following CucumberOptions annotations (this is Java/Junit version, but the idea applies everywhere)
#RunWith(Cucumber.class)
#CucumberOptions(plugin = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber.json" }, glue = {
"some.stepdef" }, features = { "src/cucumberTest/featureFiles" }, tags = { "#now" }
,dryRun = true, strict=true)
public class CucumberNowTestDryRunner {
}
The cucumber report will look like this

How to write scenario outline to capture list of object in a single argument?

When writing cucumber scenario outline test cases, sometimes i have requirement that i need one of the placeholder to hold a list of data instead of one. See below pseudo example:
Scenario Outline: example
Given I have <input_1>
When I choose <input_2>
Then I should receive <result_list> //instead of a single result
Examples:
| input_1 | input_2 | result |
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1 |
| | | result_1_case_1_part_2 |
| | | result_1_case_1_part_3 |
In the above example, my "result" need to capture a list of object for each single input_1 and input_2 parameter. But with the above writing, cucumber will not compile the last statement to something like:
#Then("....")
public void i_should_receive(Datatable or list of object) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
How can write my cucumber script to achieve what i want?
Thanks.
Scenario Outline: example
Given I have <input_1>
When I choose <input_2>
Then I should receive <result_list> //instead of a single result
Examples:
| input_1 | input_2 | result
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1,result_1_case_1_part_2,result_1_case_1_part_3 |
Then in your step definition
#Then("....")
public void i_should_receive(String result) throws Throwable {
List<String> items = Arrays.asList(str.split("\\s*,\\s*"));
}
I've been able to set a list of values in a cucumber example, this way:
Scenario Outline: The role already exists in the system, with the specified permissions
Given the user admin is logged in
And the role ADMIN with permissions <permissions> to be created
When a call to SecurityService is performed to create system roles
Then http status code 200 is returned
Examples:
|permissions |
|REGISTER_ACCOUNT,REVOKE_TOKENS,GET_ROLES,SET_ROLES|
And the concrete method:
#And("^the role ([^\"]*) with permissions ([^\"]*) to be created$")
public void theRoleWithPermissionsToBeCreated(String roleCode, List<String> permissions) {
for me, this works like a charm and I receive a list of Strings directly, without the need to parse a string value

Specflow: using same step definition for scenario and scenario outline

My feature file contains a 'scenario' test for a successful login and a 'Scenario Outline' test for testing multiple login details which should be unsuccessful.
#web
Scenario: Successful login
Given I have entered username 'tomsmith' and password 'SuperSecretPassword!' into the application
When I login
Then I should be informed that login was successful
#web
Scenario Outline: Unsuccessful login
Given I have entered username <username> and password <password> into the application
When I login
Then I should be informed that login was unsuccessful
Examples:
| testing | username | password |
| invalid combination 1 | test | test |
| special characters | $$$ | SuperSecretPassword! |
I would like both to use the same step definition (as they are just passing parameters)
My step definition is:
[Given(#"I have entered username '(.*)' and password '(.*)' into the application")]
public void GivenIHaveEnteredUsernameAndPasswordIntoTheApplication(string p0, string p1)
{
login = new LoginPage();
login.with(p0, p1);
}
The problem is that the scenario outline tests do not run, they return a 'Pending' error: Pending: No matching step definition found for one or more steps
and suggests the step definition should be:
[Given(#"I have entered test and test into the application")]
Can anyone help please?
you problem is on this line:
Given I have entered username <username> and password <password> into the application
it should be
Given I have entered username '<username>' and password '<password>' into the application
you just missed out the ' marks

BDD: SpecFlow - Scenario Outline Behaviour Not As Expected

Using scenario outlines in SpecFlow, e.g.
Scenario Outline: Invalid Login Details
Given some pre-conditions...
When user "Larry" enters username <username> and password <password>
Then the message "Invalid Login Details" should be displayed
Examples:
|username|password|
|larry06 | |
|larry06 |^&*%*^$ |
|%^&&** |pass123 |
| |pass123 |
I expected that the "When" step would be evaluated as such:
public void WhenUserEntersUsernameAndPassword(String username, String password){}
And that the scenario would be run 4 times - for each row of the table, passing the values as required. That's not the case.
Instead, SpecFlow creates 1 of 4 required step definitions:
[When(#"""(.*)"" provides the following new username larry(.*) and password ")]
public void WhenUserEntersUsernameLarryAndPassword(string p0, int p1)
{
//TODO
}
And to get the remaining 3 to 'work' I need to manually write methods explicitly matching other values in the table.
I've since realised that I can just say:
When "Larry" enters username "<username>" and password "<password>"
And I get:
[When(#"""(.*)"" provides the following ""(.*)"" and ""(.*)""")]
public void WhenUserEntersUsernameAndPassword(string p0, string name, string pass)
{
//TODO
}
Perfect.
But all documentation seems to suggest I don't need "" and that should just work (e.g. https://github.com/cucumber/cucumber/wiki/Scenario-outlines). I note:
"Your step definitions will never have to match a placeholder. They will need to match the values that will replace the placeholder"
I just don't really see the value of writing separate step definitions for each line of the table.
Is this nuance specific to SpecFlow?
When "Larry" enters username <username> and password <password>
will match
[When(#"""(.*)"" enters username (.*) and password (.*)")]
public void WhenEntersUsernameAndPassword(string p0, string name, string pass)
{
//TODO
}
so the documentation is fine.
The problem you experienced is that the auto generation of step text doesn't anticipate what regexs to insert without the "..." - which I guess it must be using as an indicator that you are passing interchangable strings - matchable with "(.*)", but if you don't want the quotes, you can still manually correct it just fine.

Resources