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

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.

Related

Get a category name from the id in the url using kusto query

I need to get the category name from category id using kusto query.
First i have got the most searched url from the website using the below kusto query and ran it in app insights logs
Requests
| where resultCode==200
| where url contains "bCatID"
| summarize count=sum(itemCount) by url
| sort by count
| take 1
From the above query i got the result like
https://www.test.com/item.aspx?idItem=123456789&bCatID=1282
So for corresponding categoryid=1282 i need to get the category name using kusto
you can use the parse operator.
for example:
print input = 'https://www.test.com/item.aspx?idItem=123456789&bCatID=1282'
| parse input with 'https://www.test.com/item.aspx?idItem=123456789&bCatID='category_id:long
parse_urlquery
print url ="https://www.test.com/item.aspx?idItem=123456789&bCatID=1282"
| extend tolong(parse_urlquery(url)["Query Parameters"]["bCatID"])
url
Query Parameters_bCatID
https://www.test.com/item.aspx?idItem=123456789&bCatID=1282
1282
Fiddle
Feedback to the OP query
Not an answer
KQL is case sensitive. The name of the table in Azure Application Insights is requests (and not Requests).
resultCode is of type string (and not integer/long) and should be compared to "200" (and not 200)
bCatID is a token and therefore can be searched using has or even has_cs, which should be preferred over contains due to performance reasons.
URLs can be used with different parameters. It might make more sense to summarize only by the Host & Path parts + the bCatID query parameter.
count is a reserved word. It can be used as alias only if qualified: ["count"] or ['count'] (or better not used at all).
sort followed by take 1 can be replaced with the more elegant top 1 by ...
requests
| where resultCode == "200"
| project url = parse_url(url), itemCount
| summarize sum(itemCount) by tostring(url.Host), tostring(url.Path), tolong(url["Query Parameters"]["bCatID"])
| top 1 by sum_itemCount

Kusto regex query for email

I am using the below Kusto query for exporting logs from App insight log
traces
| extend request = parse_json(tostring(parse_json(customDimensions).PayloadMessage))
| extend message = request.message
| extend SecondaryInfo = request.SecondaryInfo
| extend Logtype = request.Logtype
| extend File = request.File
| extend LineNo = request.LineNo
| extend MemberName = request.MemberName
| extend User = split(split(message,'User(').[1],')').[0]
| project timestamp,message,SecondaryInfo,Logtype,File,LineNo,MemberName,User
I want to extract the email address from the message column. So I am using split operation. However, I could not find the correct logic to extract the email address. Could someone please share some regex.
Below are some values in the messages column
-MMS.Core.Logging.MmsException: 1012 - Error while fetching Room Booking Requests for (User: TestAccount100#fr.domain.com) at
-MMS.Core.Logging.MmsException: 1011 - Error while fetching User's Locations (TestAccount100#fr.domain.com) at"
RbacRepository.GetUserCityBuildings-correlationId-11111fd6-e111-4d11-1111-11e101fbe111--DT-04162021T084110893-- START: (Email:TestAccount100#fr.domain.com), Cities mapped 4"
RoomBookingDetailsRepository.GetRequestDetailsAsync: Getting the BookingDetails data for User(TestAccount100#fr.domain.com), Role(Admin), IsAdmin(True), PPED() Status(), AssignedTo ()"
Below is an example that uses a naive regex.
You can go over the documentation for RE2 to adjust it, if required: https://github.com/google/re2/wiki/Syntax
datatable(s:string)
[
"-MMS.Core.Logging.MmsException: 1012 - Error while fetching Room Booking Requests for (User: TestAccount100#fr.domain.com) at",
"-MMS.Core.Logging.MmsException: 1011 - Error while fetching User's Locations (TestAccount100#fr.domain.com) at",
"RbacRepository.GetUserCityBuildings-correlationId-11111fd6-e111-4d11-1111-11e101fbe111--DT-04162021T084110893-- START: (Email:TestAccount100#fr.domain.com), Cities mapped 4",
"RoomBookingDetailsRepository.GetRequestDetailsAsync: Getting the BookingDetails data for User(TestAccount100#fr.domain.com), Role(Admin), IsAdmin(True), PPED() Status(), AssignedTo ()",
]
| extend email = extract(#"(\w+#\w+\.\w+)", 1, s)

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

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>".

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

Resources