I need to replace a value inside the URL
test/lambda-migration/v1/quote'
The v1 needs to be parameterized to take different value, and these values will come from another feature file. My code looks kike this:
Feature file -1
Scenario Outline: Lambda API registration
Given url ApiAdminURL
json myReq = read('swagger-lambda.json')
And request myReq
When method post
Then status
def responsefromsubscriber = call read('Subscriber.feature') { InvokeStatus: '#(InvokeStatus)', version: '<version>' }
match responsefromsubscriber.InvokeStatus == 200
Examples:
| responseCode | version |
| 200 | v1 |
Feature File - 2
Given url internalGateway
print 'Version: ' , version
def LocalVersion = version
print 'LocalVersion: ' , LocalVersion
And path 'test/lambda-migration/#(LocalVersion)/quote'
And header Authorization = accessTokenforInvokation
When method get
This is not replacing #(LocalVersion) to v1
And path 'test/lambda-migration/#(LocalVersion)/quote'
This is wrong. Please read this part of the docs: https://github.com/intuit/karate#rules-for-embedded-expressions
Also note that path supports a comma-delimited form:
Try:
And path 'test/lambda-migration', LocalVersion, 'quote'
Related
I am defining a variable in scenario 1 to obtain a value from response and trying to insert this as param in another scenario.
But scope of variable is till scenario. How can I use my variable from scenario1 to use in scenario 2?
you can save this data into a variable and then read it in other .feature file.
Example:
Feature1
Given path '/api/mobile'
And header Authorization = Token
When method GET
Then status 200
And match response ==
"""
{
"passes": "#number"
}
"""
* def passesResponse = response.passes
Feature2
Scenario: Update Mobile Passes For The Account
* def mobilePasses = call read('classpath:helpers/scenarios/Feature1.feature')
* def passes = mobilePasses.passesResponse
Given path '/v2/update/passes'
And request {"addPass": passes}
Given header Authorization = Token
When method PUT
Then status 200
More info you could find here: link
I am newbie in karate framework. I am trying to run my first karate test. However I am getting PolyglotException for request file even though the file exists on classpath. The error is "org.graalvm.polyglot.PolyglotException: not found: requests/first.json". The error goes away if I place request file in the features folder.
The script I have written is
Feature: Demoing scenario outline
Background:
* url 'https://reqres.in'
* def endpoint = '/api/users'
#TestId-43343
Scenario Outline: first test with scenario outline
* def name1 = <name>
* def job1 = <job>
* def requestBody = read('classpath:requests/first.json')
Given path endpoint
And request requestBody
And print requestBody
When method POST
Then status 201
And print response
And match $.job == <job>
And match $.name == <name>
Examples:
| name | job |
| 'abc' | 'DEV' |
| 'hjl' | 'DEVOPS' |
features and requests folders are present under java.
Your help is appreciated.
As mentioned here in the documentation, the default directory when you use classpath depends on how you have configured maven testResource. Try using the full path like
* def requestBody = read('classpath:src/test/java/requests/first.json')
I have feature file with a scenario that uses a variable eg: 1.
I am calling this scenario from another feature file but this time I want to pass another variable eg: 2
Feature file A: generateDocument.feature
#generatedoc
Scenario: Verify able to generate document for user
Given path somepath
And header Content-Type = 'application/json'
And request {"userId": "abc123"}
When method POST
Then status 200
* table documentId
| id | docTitle |
| '#notnull' | "ijk" |
| '#notnull' | "xyz" |
And match response[*].id == $documentId[*].id
And match response[*].title == $documentId[*].docTitle
Feature file B: useDocument.feature
call read('generateDocument.feature#generatedoc') { userId: 'abc456'}
So when I run feature file A, it should use the variable 'abc123', but when I run the feature file B, it should use the variable 'abc456'
But currently when I run feature file B, it still uses 'abc123'
Please do this in A - so it becomes a re-usable feature.
And request {"userId": "#(userId)"}
Now you need to call it 2 times (maybe in 2 different features and it will work):
Feature B:
call read('generateDocument.feature') { userId: 'abc456' }
Feature C:
call read('generateDocument.feature') { userId: 'abc123' }
Given i have something like this:
Scenario Outline: test
Given request {"movie":"<title>","age":"<age>"}
When method post
Then status 201
Then match response contains {"something": 52.0833} || {"something": 27.160493}
Examples:
| title | age
| test | 30
| test1 | 40
Now i'd like to verify that the given response 52.0833 and 27.160493 are present in each response body.
Given that these are run in parallel, does karate have a way of saving both requests to a variable or doing something like i tried above i.e using || operator or 'either'.
This will work, refer the docs: https://github.com/intuit/karate#self-validation-expressions
Given def response = { something: 52.0833 }
Then match response contains { something : '#? _ == 52.0833 || _ == 27.160493' }
You should never consider saving responses to a file, always validate then and there and move on.
From Feature file 1, i am reading the content of a json file and passing it to the serverpost.Feature
feature file 1
* def output = read('output.json')
* def result = call read('serverpost.feature') output
In feature file 2, i am trying to set the Path as TC_ID and request body as BODY from the json data.
However, i am not able to set the path using the below feature. Please assist
Feature file 2
Given path '#(TC_ID)'
Given url 'http://myappurl.com:8080/mytestapp/Servers/Data/uploadServer/'
And request { some: '#(BODY)' } #### Here i am able to get the BODY data from JSON
When method post
Then status 200
The '#(foo)' notation applies only to JSON, XML or the right-hand-side of a match statement.
Please use it like a normal JS expression:
Given path TC_ID
or
Given path output.TC_ID