How to escape brackets in Cucumber JS Scenario Outline? - cucumber

Using Cucumber-JS and I am trying to validate a system response in scenario outline which has brackets ().
Wondering what is the right way to escape below statement, as I have tried few options but doesn't seem to work around the "(domestic or overseas)" bit
Then I make POST requests to the until the JSON response body has:
| key | value |
| errors[0].message | A maximum of 6 cities (domestic or overseas) are permitted |
Options tried:
| A maximum of 6 cities \(domestic or overseas\) are permitted |
| A maximum of 6 cities \(\domestic or overseas) are permitted |
| A maximum of 6 cities \(domestic\ or overseas\) are permitted |
| A maximum of 6 cities \(domestic or overseas\)\ are permitted |
Any ideas as how this might be handled?

Related

In Azure Application Gateway, is it possible to do math operations when rewriting URLs/Query Strings?

I am designing a service that needs to route requests based on the remainder from the division of a path or query string parameter by a constant value. For example, let's say the incoming address looks like abc.com/1234 and that the constant's value is 5.
Here is a list of sample incoming requests paths, underlying expression, and desired routes:
| Incoming | Expression | Route |
|:---------|:----------:| -----:|
| abc.com/10 | 10 % 5 = 0 | xyz-0.com |
| abc.com/11 | 11 % 5 = 1 | xyz-1.com |
| abc.com/12 | 12 % 5 = 2 | xyz-2.com |
| abc.com/17 | 17 % 5 = 2 | xyz-2.com |
This question mentions the same kind of rewrite/redirect, but regex replace seems to not be supported.
Would it be possible to achieve this with Azure Application Gateway rewrites (or Azure Front Door; looks to have the same capabilities as AG as far as rewrites go)?

Cognos : create custom groups in report studio

I am new to Cognos and I know SQL but it seems I can’t figure out cognos logic for some basic stuff. It's been two days I am trying and I have been looking all over the internet without finding anything.
Here’s the problem.
I have a Dimension Product that has two dimensions under it: type of product and article (in this order, article is below type of product in terms of hierarchy).
Let’s simplify and say I have this table:
Product line | Article | Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Article3 | 10
| Article4 | 20
| Article5 | 30
Bags | Article6 | 100
| Article7 | 100
| Article8 | 30
Balls | Article9 | 50
| Article10 | 50
I want to display the sales per product line and per article for article1 and article2 and the sales per product line only for the rest.
I want my final result to look like this:
Product line | Article | Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Other | 60
Bags | Other | 330
Balls | Other | 100
I created an elementary data with the following expression “if [article-name] in (‘article1’,’article2’) then ([article-name]) else (‘other’) but it gives me this:
Product line | ArticleNEW| Sales
-------------------------------
Shoes | Article1 | 1000
| Article2 | 2000
| Other | 10
| Other | 20
| Other | 30
Bags | Other | 100
| Other | 100
| Other | 30
Balls | Other | 50
| Other | 50
I thought Cognos would group by automatically but it seems it does not when you create a new expression….
Please note that I have thousands of articles and I cannot create a data that would say “article3+article4+article5 etc.”.
If anyone has an idea on this, it would be great!
Thank you in advance!
I believe the issue is with the model. If you have access to Framework Manager and the project/metadata, this would change my answer
Try this method: 3 queries
1) Query 1 just have product line and article
2) Query 2 product line, article, sales
3) Next go to queries, then tool box, find the join.
Drag that over. There will be spots to add query 1 and query 2
In the middle is how you define the join
Connect the product line and article (there should be a button to add links so you should have 2 lines). This will be 1 to many (1.1 to 1.n). The first part represents the type of join, 1 being inner, 0 being outer. The second part is the relationship (either 1 or n for many).
We can group by query 1 and aggregate query 2 the way we want
Double click on query 3 and drag the data items (from query 1 and query 2)
Grab sales from query 2, and everything else from query 1
Now you should be able to set the aggregate property for Sales (either total or sum)

Cucumber: nested scenario outline cycles

Scenario to automate:
Given <precondition> was fulfilled
And <user> is authorized
When user requests <endpoint>
Then user should receive <code> response
Test data matrix:
| precondition | endpoint | user1 | user 2 | ....
| | /users | OK | Not Found |
| | /roles | OK | OK |
| | /create_user | OK | OK |
| object user exists | /update_user | OK | OK |
| object user exists | /delete_user | OK | OK |
| | /create_data_role | OK | Not Found |
| data role exists | /update_data_role | OK | Not Found |
....
There's around 20 users with different role combination and around 20 endpoints.
Need to verify each endpoint for each user - so it should be a nested cycle.
How do I do it?
Don't do this in Cucumber - reasons
1) You get no benefit from putting all these routes and conditions in Gherkin. Nobody can read them and make sense of them especially if you trying something combinatorial
2) Cuke scenarios run slowly, and you want to run lots of them, you could dramatically reduce your run time by writing a fast unit test instead.
3) If you write this test in code you can write it much more elegantly than you can in Gherkin.
4) Dealing with errors is painful (as you've already pointed out)
You are using the wrong tool for this particular job, use something else.
Yet I come up with this option, but it doesn't follow gherkin convention because When and Then steps a jammed in one
1. Preconditions moved to #Before hook
2. Scenario
Given <user> is authorized
Then <user> requests functionality appropriate response code should be received
| ENDPOINT | USER1 | USER2|
| /users | 200 | 404 |
| /create_user | 200 | 404 |
| /update_user | 200 | 404 |
Examples:
| username |
| USER1 |
| USER2 |
It's also inconvenient because when tests failed it takes time to identify faulty endpoint(S)

Should all fields that are visible on a screen be validated in Gherkin?

We are creating Gherkin feature files for our application to create executable specifications. Currently we have files that look like this:
Given product <type> is found
When the product is clicked
Then detailed information on the product appears
And the field text has a value
And the field price has a value
And the field buy is available
We are wondering if this whole list of and keywords that validate if fields are visible on the screen is the way to go, or if we should shorten that to something like 'validate input'.
We have a similar case in that our service can return a lot of 10's of elements for each case that we could validate. We do not validate every element for each interaction, we only test the elements that are relevant to the test case.
To make it easier to maintain and switch which elements we are using, we use scenario outlines and tables of examples.
Scenario Outline: PO Boxes correctly located
When we search in the USA for "<Input>"
Then the address contains
| Label | Text |
| PO Box | <PoBox> |
| City name | <CityName> |
| State code | <StateCode> |
| ZIP Code | <ZipCode> |
| +4 code | <ZipPlus4> |
Examples:
| ID | Input | PoBox | CityName | StateCode | ZipCode |
| 01 | PO Box 123, 12345 | PO Box 123 | Boston | MA | 12345 |
| 02 | PO Box 321, Whitefish | PO Box 123 | Whitefish | MN | 54321 |
By doing it this way, we have a generic step "the address contains" that uses the 'Label' and 'Text' to test the individual elements. It is a neat and tidy way to test a lot of potential combinations - but it probably depends on your individual use case - how important all of the fields are.
You only need to validate the ones that provide business value, which is probably all of them. I would avoid using tech terms like "field" because it isn't related to a behavior. Al Mills is right on for using the tables.
I'd word it like this:
Scenario Outline: Review product details
Given I find the product <Type>
When I select the product
Then detailed information on the product appears including
| Description | <Description> |
| Price | <Price> |
And I can buy the product
Examples:
| Type | Description | Price |
| Hose | Rubber Hose | 31.99 |
| Sprinkler | Rotating Sprinker | 12.99 |
The words I chose are behaviors or whats, not technical implementations or hows.

What are the Lexing Errors in Cucumber?

I was trying to run a simple Feature file but i was getting Exception like :
Exception in thread "main" cucumber.runtime.CucumberException: Error parsing feature file.
which is Caused by: gherkin.lexer.LexingError: Lexing error
i am trying to parametrized a When statement and got this Exception:
Scenario: Login to Gmail
Given User is on Gmail login page
When User enters <userName> and <pwd>
And Clicks on login button
Then User should redirect to home page
scenario outline(tried Examples as well but didn't worked):
|userName | pwd |
|ravivani10 | abc |
The correct syntax for a scenario outline is to start with the keyword Scenario Outline: and list the examples with the Examples: keyword.
Scenario Outline: Login to Gmail
Given User is on Gmail login page
When User enters <userName> and <pwd>
And Clicks on login button
Then User should redirect to home page
Examples:
| userName | pwd |
| ravivani10 | abc |
I had this same problem but I was using correct syntax. Turns out my formatting was wrong, yes you read correctly: formatting. My scenario looked like this:
Scenario Outline: Confirm that hitting the endpoint returns the expected data
Given uri url/to/a/service/to/test/param/{interval} and method GET
And system user
When I call the web service
Then I expect that 'http status is' '200'
And the following rules must apply to the response
| element | expectation | value |
| $ | is not null | |
| objectType | value = | Volume |
| objectData | is not null | |
| objectData | count = | 1 |
| objectData[0].value | is not null | |
| objectData[0].value | data type is | float |
| objectData[0].value | value = | <value> |
Examples:
| interval | value |
| int1 | 355.77 |
| int2 | 332.995 |
| int3 | 353.71125 |
Above test will fail with Lexing Error. Now take a look at the indentation of the Example piece of my test (it is indented one level down the Scenario Ouline).
If I indent my test as follows (same level as Scenario Outline):
Scenario Outline: Confirm that hitting the endpoint returns the expected data
Given uri url/to/a/service/to/test/param/{interval} and method GET
And system user
When I call the web service
Then I expect that 'http status is' '200'
And the following rules must apply to the response
| element | expectation | value |
| $ | is not null | |
| objectType | value = | Volume |
| objectData | is not null | |
| objectData | count = | 1 |
| objectData[0].value | is not null | |
| objectData[0].value | data type is | float |
| objectData[0].value | value = | <value> |
Examples:
| interval | value |
| int1 | 355.77 |
| int2 | 332.995 |
| int3 | 353.71125 |
Above test will pass. Totally dumb to me but that's how it works.
This can be caused by not having the final | at the end of each line of data. That's not the reason for the OP but might help someone else.
A lexing error from cucumber just means that the feature file wasn't in the format that cucumber is expecting. This could be things like having a scenario title with no content or having the title "Feature: blah" twice. This will happen even if the error isn't in the scenario that you are running.
The lexing error will usually give you a line number. Can you post the line it complains about please?
I got the same error and it was caused by having a space between the word 'Outline' and the colon symbol
Scenario Outline : Convert currencies
When I removed the space, I had this:
Scenario Outline: Convert currencies
..and the issue got resolved.
To find out the offender, check your error logs and you will find in the output the line number where the error lies. I hope this helps someone
You need to do a couple of things: A) remove the spaces in Feature : and Scenario Outline : keywords; and B) change the Scenario Outline to Scenario (or add the missing examples for the outline).
If you run this feature:
Feature: Proof of concept that my framework works
Scenario: My first Test
Given this is my first test
When This is my second step
Then This is the final step
Then cucumber will output the to-be-completed step definitions:
You can implement step definitions for undefined steps with these snippets:
Given(/^this is my first test$/) do
pending # Write code here that turns the phrase above into concrete actions
end
When(/^This is my second step$/) do
pending # Write code here that turns the phrase above into concrete actions
end
Then(/^This is the final step$/) do
pending # Write code here that turns the phrase above into concrete actions
end

Resources