Scenario Outline: Verify retreiving endpoint for particular system
Given path 'kites/<id>'
When method get
Then status 200
And match response contains "<orgid>"
Examples:
| kites | orgid |
| 56338e32e4b0846c32c0732e | 56338e32e4b0846c32c0732e |
I am getting the following error:
com.intuit.karate.exception.KarateException: path: $, actual:
{
"orgId": "56338e32e4b0846c32c0732e",
"name": "Supplier Management"
}
expected: '56338e32e4b0846c32c0732e', reason: actual value is not a string
I tried with <orgid> and "<orgid>" but i am getting the same error.
Any help would be appreciated.
There are so many things I don't understand in your example. Where did <id> come from ? Where is the kites column used ?
The most serious problem is you are using orgid but the actual JSON has a key orgId. Please don't make basic mistakes and try again.
And shouldn't you be trying to do something like this:
And match response contains { orgId: "<orgid>" }
Edit: Since there are complaints about the above (which I find disappointing), I'm adding another option:
And match response.orgId == "<orgid>"
Related
This question already has an answer here:
The json key is not being omitted where the cells are empty in examples of Scenario Outline .What change needs to be done?
(1 answer)
Closed 1 year ago.
I read in the Karate documentation that if one uses "null", it will result in the key being omitted from the call. However, if one still wants to force a null, they could wrap it in parentheses like: "(null)".
It does go through with the key. However, on the actual call, the key is still omitted from the parameters. How can I force it there as well? Is it LITERALLY the same thing as an empty string?
I.e:
| Environment| Application| Version | status |
| Environment| Application| (null) | 401 |
call read....
Results:
{
"Environment": "Environment",
"Application": "Application",
"Version": "null",
"status": 401
}
But the URL looks like:
GET https://?Environment=Environment&Application=Application
Please advise.
EDIT below for a better example:
In my "primary" file, I have the following:
* table requestTable
| q | um | ie | status |
| (null) | 1 | utf | 400 |
Where all three params (q, um, ie) are required parameters.
My "secondary" runner file, looks like the following:
* def requiredParams = { q: '#(q)', um: '#(um)', ie: '#(ie)'}
* def mainUrl = 'https://www.google.com'
* def apiPath = '/search'
Given url mainUrl
And path apiPath
And params requiredParams
When method GET
Then status 400
I am expecting a 400 since a required param is required. It doesn't get sent as "null", even if I use (null), it removes that field altogether in the actual call. This example obviously won't work in real life since I am using example google stuff. I apologize about that. If you still need a real life example, please show me how I can do it.
I assume that you are talking about Examples: but your question is incomplete.
Try this: https://github.com/karatelabs/karate#scenario-outline-enhancements
Examples:
| Version! |
| '' |
I am able to get the multiple events (api's logs) in splunk dashboard like below
event-1:
{ "corrId":"12345", "traceId":"srh-1", "apiName":"api1" }
event-2:
{ "corrId":"69863", "traceId":"srh-2", "apiName":"api2" }
event-3:
{ "corrId":"12345", "traceId":"srh-3", "apiName":"api3" }
I want to retrieve corrId (ex:- "corrId":"12345") dynamically from one event (api log)by providing apiName and build splunk search query based on retrieved corrId value that means it will pull all the event logs which contains same corrId ("corrId":"12345").
Output
In above scenario expected results would be like below
event-1:
{ "corrId":"12345", "traceId":"srh-1", "apiName":"api1" }
event-3:
{ "corrId":"12345", "traceId":"srh-3", "apiName":"api3" }
I am new to splunk, please help me out here, how to fetch "corrId":"12345" dynamically by providing other field like apiName and build Splunk search query based on that.
I have tried out like below, but to no luck.
index = "test_srh source=policy.log [ search index = "test_srh source=policy.log | rex field=_raw "apiName":|s+"(?[^"]+)" | search name="api1" | table corrId]
This query gives event-1 log only but we need all other events which contain same corrId ("corrId":"12345"). Appreciate quick help here.
Given you're explicitly extracting the apiName field, I'll assume the corrId field is not automatically extracted, either. That means putting corrId="12345" in the base query won't work. Try index=test_srh source=policy.log corrId="12345" to verify that.
If the corrId field needs to be extracted then try this query.
index=test_srh source=policy.log
| rex "corrId\\":\\"(?<corrId>[^\\"]+)"
| where [ search index = "test_srh source=policy.log
| rex "apiName\":\"(?<name>[^\"]+)"
| search name="api1"
| rex "corrId\\":\\"(?<corrId>[^\\"]+)"
| fields corrId | format ]
Note: I also corrected the regex to properly extract the apiName field.
I have a very large response array I want to assert against, but without knowing the order. I have a variable with the expected response values so I can do a single giant comparison, but I'm unable to load the entire response and compare it with the entire expected response variable at the same time.
* def obligationsQuery = Java.type("tests.account.sql.Obligations").getObligations(division, account)
* def getObligations = db.readRows(obligationsQuery)
Given path "account", "v1", "accounts", systemId, "obligations"
And header api-key = gatewayKey
When method GET
Then status 200
And match $.data != null
And match $.data[*].transactionType contains any "<transactionTypeResponse>"
And match $.data[*] contains only getObligations
Examples:
| description | transactionType | transactionTypeResponse |
| Invoice | 001 | invoice
The error I get is:
get_obligations_collection.feature:49 - path: $.data[*][*], actual: [{"object1"}, {"object2"}, {"etc"}], expected: {"object1"}, reason: actual value does not contain expected
I've also tried:
And match each $.data[*] contains only getObligations
But then I get:
get_obligations_collection.feature:49 - path: $[0], actual: [{"object1"}, expected: [{"object1"}, {"object2"}, {"etc"}, reason: actual value is not list-like
I assume $.data is a JSON array so no need to use json-path to again get the data into another array by calling as $.data[*].
so,
And match $.data contains only getObligations
should work.
If this still not working, please provide some proper response and getObligations values to investigate further.
I assumed that contains only would show the complete value of my variable, but smartly, it only shows the object that fails to match the api response object. Was able to verify that through a simpler assert, and then checking the error message saw that an ID was missing padding that the API adds, but the DB does not.
As usual, just looking more closely at the data returned provides a simple explanation.
While using data-driven feature in Karate framework, I see the generated report just show the title as configured in Scenario Outline NOT attached the value using in Example table. It causes the Tester confuse which data is using, and take time to expand each scenarios to know which data is using; so I want the report can pass variable into the title - Scenario/Scenario Outline. Please take a look at the example below.
E.g.
Feature: Login Feature
Background:
* configure headers = { 'Webapp-Version': '1.0.0'}
Scenario Outline: As a <description> user, I want to get the corresponding response_code <status_code>
Given def path = 'classpath:features/Authentication/authentication.feature'
And def signIn = call read(path) {username: '<username>', password: '1234567890'}
Then match signIn.status == <status_code>
Examples:
|username | status_code| description |
|test#gmail.com | 200 | valid user |
|null | 400 | invalid user|
My expected result, the generated report should fill the value on table for field "status code" and "description" fields.
-> As a valid user user, I want to get the corresponding response_code 200.
Please share your ideas and comments on it.
Thanks,
Learn.
Not supported. Just use the print syntax and you will see it in the report.
EDIT: okay this will be possible in the next version: https://github.com/intuit/karate/issues/553
This question already has an answer here:
Check 2 differents status with Karate
(1 answer)
Closed 1 year ago.
I'm doing data driven test with Karate, and met a block issue. The REST API response body is in different structure with different status. For example, when the status is 200, the response body is JSON array. When the status is 4** and 5***, the response body either is string or blank. I hope to check the response conditionally using the blow code. But seems it doesn't work.
"* eval if (verInfo.statusCode == 200) (match each response contains any verInfo.respBody) //verInfo.statusCode and verInfo.respBody is from the test data(DDT)
* eval if (verInfo.statusCode != 200) match response contains verInfo.respBody"
First, you cannot mix Karate script and JavaScript like this.
Second I suggest you use the responseStatus built-in variable. I also suggest using proper data-driven approaches instead of over-engineering your tests with conditional logic.
So you can do this, (and there are many other ways if you go through the docs and examples):
Scenario Outline:
Given url 'http://foo.bar'
And request <req>
When method post
Then match responseStatus == <code>
And match response == <body>
Examples:
| req | code | body |
| 'a' | 200 | 'foo' |
| 'b' | 400 | '' |