Karate - How to pass a variable to another feature file using table [duplicate] - api

This question already has an answer here:
Karate - How to call multiple external features from a single main feature
(1 answer)
Closed 1 year ago.
After doing some reading, I have figured out how to send variables to another feature file. However, how do I pass a variable when I am using a table?
The setup is:
* table valueTable
| number | mode | time | status |
| 12345 | mobile | 100 | 200 |
* call read('feature1.feature#scenario1') valueTable
So if I use the following line to pass variable through, I get failures:
* call read('feature1.feature#scenario1') {table1: '#(valueTable)', payload1: '#(payload)'}
Of course in above, 'payload' is the variable I want to pass to the second feature file. I don't have any issues passing variables if there is no table involved.
Please advise.

Works for me. Put this in a new feature:
* table valueTable
| number | mode | time | status |
| 12345 | 'mobile' | 100 | 200 |
* call read('called.feature') { table1: '#(valueTable)' }
And in called.feature have this:
#ignore
Feature:
Scenario:
* print __arg
And it works fine. So if you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Related

Print logs only when the tests failed in karate

With Karate API tests, I would like to print the request and reponse only when the test fails.
How can I achieve that in karate.
Consider the below scenarios
Feature: Validate Addition.
Background:
Scenario Outline: Verify Addition
* def sum = <num1> + <num2>
And match sum == 10
* print "number1:" + num1 + " number2:" + num2
Examples:
| num1 | num2 |
| 5 | 5 |
| 7 | 3 |
| 3 | 8 |
| 1 | 5 |
| 1 | 9 |
In the above scenario I get the print for every iteration. Is it possible to print the numbers only when the match fails.
I think it would be more efficient if we can have such option.
Short answer is that it is not possible. You can try contributing code to make this happen. Or maybe you should use REST-assured or Selenium - those sound more like a good fit for you, based on all your questions.
One thought is that you can switch off all logging by making the levels ERROR etc. and then write some custom hook. Refer to hooks here: https://stackoverflow.com/a/60944060/143475
Also refer to how to create custom reports here: https://stackoverflow.com/a/66773839/143475

In cucumber feature file, scenario outline table can have < >-delimited parameters of Examples

Please tell me if this is possible to have angle parameter in the table of Example (of Scenario Outline). I am new in feature file development hence need your help.
Feature: Testing table can have angle parameter of examples
Scenario Outline: outline
When a table step:
| Day | Months |
| 30 | <Months> |
Then verify if day exist in this month<DoesContainInThisMonth>
Examples:
| Months | DoesContainInThisMonth |
| Jan | No |
| Feb | No |
| Mar | Yes |
I do not have a straight solution to this problem the way you are looking for.
But maybe a different approach could help.
To give an example: in the column "Months" you could have a list of months that meet each requirement ("Days"?). And then, check if a specific month is included in this list in the StepDefinitions code. This way, you only need one table.
In my opinion that makes the test more clear, which is one of the benefits of BDD.
If you provide more information about the objective of this scenario, it is likely more contributing answers will come up.

How do i parameterize parameters i am passing in my API request & execute through Karate?

I am testing API's for my application & each API has multiple parameters to be passed, ex. below:
https://abc.xyz.com/***.svc/restful/GetSummary?FromDate=2019/06/28&ToDate=2019/06/28&CompAreaId=15&RegId=4
Each parameter in the request has multiple values (within a defined set of values), so if I want to parameterize each parameter with all the values it could possibly have, how can I create a scenario that will help me achieve this?
I would appreciate any hints/views.
I have been passing parameters as shown in the code below, but unable to pull off the scenario above mentioned, it would be time-consuming & repetitive to pass parameters in a separate scenario each time.
Scenario: Verify if GetContext API returns data with params
Given path 'GetContext'
And param FromDate = '2019/06/27'
And param ToDate = '2019/06/27'
And param CompAreaId = 20
And param RegId = 4
When method get
Then status 200
* def res = response
* print 'response:', response
You can use “Scenario Outline” to achieve that. The following modified code below will run for the 3 rows in the example. (related link: https://github.com/intuit/karate#the-cucumber-way)
Scenario Outline:
Given path 'GetContext'
And param FromDate = '<FromDate>'
And param ToDate = '<ToDate>'
And param CompAreaId = <CompAreaId>
And param RegId = <RegId>
When method get
Then status 200
* def res = response
* print 'response:', response
Examples:
| FromDate | ToDate | CompAreaId | RegId |
| 2019/06/27 | 2019/06/27 | 20 | 4 |
| 2019/06/28 | 2019/06/28 | 21 | 5 |
| 2019/06/29 | 2019/06/29 | 22 | 6 |
Instead of a static count, if you have a dynamic number of rows, you can store the parameter values in a json or CSV and reference it in the example. (related link: https://github.com/intuit/karate#dynamic-scenario-outline)

ID Extracted from string not useable for connecting to bound form - "expression ... too complex"

I have a linked table to a Outlook Mailitem folder in my Access Database. This is handy in that it keeps itself constantly updated, but I can't add an extra field to relate these records to a parent table.
My workaround was to put an automatically generated/added ID String into the Subject so I could work from there. In order to make my form work the way I need it to, I'm trying to create a query that takes the fields I need from the linked table and adds a calculated field with the extracted ID so it can be referenced for relating records in the form.
The query works fine (I get all the records and their IDs extracted) but when I try to filter records from this query by the calculated field I get:
This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.
I tried separating the calculated field out into three fields so it's easier to read, hoping that would make it easier to evaluate for Access, but I still get the same error. My base query is currently:
SELECT InStr(Subject,"Support Project #CS")+19 AS StartID,
InStr(StartID,Subject," ") AS EndID,
Int(Mid(Subject,StartID,EndID-StartID)) AS ID,
ProjectEmails.Subject,
ProjectEmails.[From],
ProjectEmails.To,
ProjectEmails.Received,
ProjectEmails.Contents
FROM ProjectEmails
WHERE (((ProjectEmails.[Subject]) Like "*Support Project [#]CS*"));
I've tried to bind a subform to this query on qryProjectEmailWithID.ID = SupportProject.ID where the main form is bound to SupportProject, and I get the above error. I tried building a query that selects all records from that query where the ID = a given parameter and I still get the same error.
The working query that adds Support Project IDs would look like:
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
| ID | Subject | To | From | Received | Contents |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
| 1 | RE: Support Project #CS1 ID Extra... | questions#so.com | Isaac.Reefman#so.com | 2019-03-11 | Trying to work out how to add... |
| 1 | RE: Support Project #CS1 ID Extra... | isaac.reefman#so.com | questions#so.com | 2019-03-11 | Thanks for your question. The... |
| 1 | RE: Support Project #CS1 ID Extra... | isaac.reefman#so.com | questions#so.com | 2019-03-11 | You should use a different me... |
| 2 | RE: Support Project #CS2 IT issue... | support#domain.com | someone#company.com | 2019-02-21 | I really need some help with ... |
| 2 | RE: Support Project #CS2 IT issue... | someone#company.com | support#domain.com | 2019-02-21 | Thanks for your question. The... |
| 2 | RE: Support Project #CS2 IT issue... | someone#company.com | support#domain.com | 2019-02-21 | Have you tried turning it off... |
| 3 | RE: Support Project #CS3 email br... | support#domain.com | someone#company.com | 2019-02-12 | my email server is malfunccti... |
| 3 | RE: Support Project #CS3 email br... | someone#company.com | support#domain.com | 2019-02-12 | Thanks for your question. The... |
| 3 | RE: Support Project #CS3 email br... | someone#company.com | support#domain.com | 2019-02-13 | I've just re-started the nece... |
+----+--------------------------------------+----------------------+----------------------+------------+----------------------------------+
The view in question would populate a datasheet that looks the same with just the items whos ID matches the ID of the current SupportProject record, updating when a new record is selected. A separate text box should show the full content of whichever record is selected in that grid, like this:
Have you tried turning it off and on again?
From: support#domain.com
On: 21/02/2019
Thanks for your question. The matter has been assigned to Support Project #CS2, and a support staff member will be in touch shortly to help you out. As it is considered of medium priority, you should expect daily updates.
Thanks,
Support
From: someone#company
On: 21/02/2019
I really need some help with my computer. It seems really slow and I can't do my work efficiently.
Neither of these things happens as when I try to use the calculated number to relate to the PK of the SupportProject table...
I don't know if this is a part of the problem, but whether I use Int(Mid(Subject... or Val(Mid(Subject... I still apparently get a Double, where the ID field (as an autoincrement ID) is a Long. I can't work out how to force it to return a Long, so I can't test whether that's the problem.
So that is output resulting from posted SQL? I really wanted raw data but close enough. If requirement is to extract number after ...CS, calculate in query and save query:
Val(Mid([Subject],InStr([Subject],"CS")+2))
Then build another query to join first query to table.
SELECT qryProjectEmailWithID.*, SupportProject.tst
FROM qryProjectEmailWithID
INNER JOIN SupportProject ON qryProjectEmailWithID.ID = SupportProject.ID;
Filter criteria can be applied to either ID field.
A subform can display the related child records synchronized with SupportProject records on main form.
I tested the ID calc with your data and then with a link to my Inbox. No issue with query join.

how to increment field value each time selenium test is run?

is there any simple way to increment for example field value by +1 every time Selenium test is run through Selenium IDE?
Command: Type
Target: some kind of id
Value: number+1
EDIT 1 :thanks for a reply krosenvold. i got your idea and this is a simplified version of what i got so far:
...
store | 10 | x
storeEval | storedVars['x'] = ${x}+1 |
...
variable's x value does realy get incremented, but how would you save that value between distinct test runs? is it even possible?
should i get $x value every time the test is run and at the end of it assign $x value to some dummy element on testing page, so i could retrieve that previously incremented value the next time test is run?
Correct Answer
store | 10 | i
store | javascript{storedVars.i++;} | i
echo | ${i}
This is solution for your problem
store | 10 | i
store | javascript{storedVars.i++;}
echo | ${i}
store | 0 | iterator
echo | ${iterator} |
execute script | return parseInt(${iterator}) + 1 | iterator
echo | ${iterator} |
As result will be:
0
1
You can use eval;
eval($('elementId').value = $('elementId').value +1);
The exact syntax I'm showing implies prototype on the client;
document.getElementById('elementId').value should also do the trick in a standard DOM environment.
This worked for me
storeEval | storedVars['nextRow'] = ${nextRow}+1 |