karate

Using response data from one scenario to another

那年仲夏 提交于 2019-12-11 12:27:23
问题 With Karate, I'm looking to simulate an end-to-end test structure where I do the following: Make a GET request to specific data Store a value as a def variable Use that information for a separate scenario This is what I have so far: Scenario: Search for asset Given url "https://foo.bar.buzz" When method get Then status 200 * def responseItem = $.items[0].id // variable initialized from the response Scenario: Modify asset found Given url "https://foo.bar.buzz/" + responseItem // making request

Is there a way to randomize the jsonPath array number in get[] myJson?

岁酱吖の 提交于 2019-12-11 12:25:18
问题 I have a list of values that I can use for the title field in my json request. I would like to store a function in the common.feature file which randomizes the title value when a scenario is executed. I have attempted using the random number function provided on the commonly needed utilities tab on the readme. I have generated a random number successfully, the next step would be using that randomly gernerated number within the jsonpath line in order to retrieve a value from my data list which

Why operator '+' inside functions does not modify * def made variables?

五迷三道 提交于 2019-12-11 12:12:44
问题 I'm trying to process a list of json-s that I got as an answer from an API. [ { "originalEstimate": "16h", "remainingEstimate": "9h", "timeSpent": "7h" }, { "originalEstimate": "64h", "remainingEstimate": "63h", "timeSpent": "1h" } ] I have to sum the fields and I came up with a code for it, but it seems like it does not modify the mySum variable. For this example, I just used the 'originalEstimate'. I tried to add manually the elements and that works. Ex.: (parseFloat(getNum(json[0]

Karate 0.9.1 - Exception in thread “main” java.lang.StackOverflowError

元气小坏坏 提交于 2019-12-11 11:59:40
问题 When I'm trying to run *.feature file or a single scenario with "right-click" (IntelliJ Idea), I've always received an exception: Exception in thread "main" java.lang.StackOverflowError at java.util.HashMap.<init>(HashMap.java:457) at java.util.LinkedHashMap.<init>(LinkedHashMap.java:347) at java.util.HashSet.<init>(HashSet.java:162) at java.util.LinkedHashSet.<init>(LinkedHashSet.java:154) at jdk.nashorn.internal.runtime.ScriptObject$KeyIterator.init(ScriptObject.java:2467) at jdk.nashorn

Karate: when I want to set value to $..somewhereInJsonPath I get Path must not end with a '

为君一笑 提交于 2019-12-11 11:47:01
问题 I want to update a value of somewhereInJsonPath field in my JSON file. I am using for this: * set myBody $..someWhereInJsonPath = 'AAA' . And when I run test I get: Path must not end with a '.' But when I am using * set myBody $..firstHere.someWhereInJsonPath = 'AAA' it is working. I think in first case, where we want to update first value in $.., it must working too. To clarify: For example we have JSON: { "store": { "book": [ { "category": "fiction", "author": "Evelyn Waugh", "title":

Karate API Tests - API POST request unable to send body when Content-Type is application/jwt

ⅰ亾dé卋堺 提交于 2019-12-11 11:46:43
问题 For POST api having body as jwt karate is unable to send body having content-type as application/jwt. Whereas while i perform the same through Postman it works. Let me know if i am missing anything. My API request is: 1 > POST "Sever URL" 1 > Accept-Encoding: gzip,deflate 1 > Connection: Keep-Alive 1 > Content-Length: 4959 1 > Content-Type: application/jwt 1 > Host: auth-sandbox.apiboitest.com 1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_144) here the body is not getting passed which

String.split() in Karate Feature File returning exceptions

六月ゝ 毕业季﹏ 提交于 2019-12-11 10:26:06
问题 I'm unsure about how I can split the response string from an already created feature to obtain the response header "Location" value. What I've tried 1) Feature: Create Tariff Background: * def result = call read('../../get-user-token.feature') * def serviceId = call read('create-service.feature') Scenario: Create Tariff Given url 'https://app-dev.topbox.pro/tariff-svc/api/v1/tariffs' And header Authorization = result.response.token_type + " " + result.response.access_token And request """ {

Schema Validation - Karate expression to check if value exists in array

[亡魂溺海] 提交于 2019-12-11 10:06:52
问题 Sample Response { "data": [ { "name": "DJ", "status": "ACTIVE" } ] } Sample Feature File @ignore Feature: Sample @smoke Scenario: Karate expression to check if value exists in array Given url url And path '/test' When method GET Then status 200 And def users = response.data And def possibleStatus = ["ACTIVE", "INACTIVE"] And def schema = """ { name: '#string', status: ? } """ And match each users contains schema Is there a way to check if status is either ACTIVE or INACTIVE using karate

Is it possible to do soft assertion in the karate

无人久伴 提交于 2019-12-11 09:55:28
问题 Is it possible to continue the execution of test step even if one of the assert/match fails? Ex: Scenario: Testing * def detail = {"a":{"data":[{"message":["push","dash"]},{"message":["data","Test"]}]}} * match detail contains {"a":{"data":[{"message":["push","dash"]}]}} * print detail Here match will fail but execution stop at that point. is there a way to do a soft assertion so that next step gets executed? 回答1: If you use a Scenario Outline each "row" is executed even if one fails.

Passing data between scenarioes in karate

拟墨画扇 提交于 2019-12-11 09:49:31
问题 I have a requirement to pass the response of first web services to next service. We maintain one scenario for each web services. Some of the tags in first services needs to be passed to next web services within the feature file itself. Please help. Thanks, Thiyagu 回答1: I think you have fundamentally misunderstood the way a Scenario works. Each Scenario is supposed to be independent. You can't have one Scenario update a variable and then expect that other ones can see the updated value. Please