karate

how to call a sql script or query in background for a Karate feature?

喜你入骨 提交于 2019-12-20 03:34:32
问题 I have Karate feature with a long list of operations. I need to manually have some test data setup before running these tests which is essentially one sql query. Is there a way we can have this query run in "background" in Karate? I'm trying to update all the values in status which aren't "ready_to_test" to "ready_to_test". Say my query is update my_table set status = 'ready_to_test' where status != 'ready_to_test'; EDIT: I am trying to run the update query as follows use JDBC to setup test

How to send a byte array as a past of Json with karate framework

十年热恋 提交于 2019-12-20 03:16:30
问题 I have an endpoint who consumes Json with 2 attributes, like {id='12344', data=byte_array} so I've wrote a test Feature: submitted request Scenario: submitted request * def convertToBytes = """ function(arg) { var StreamUtils = Java.type('my.utils.StreamUtils'); // it reads stream and convert it to a byte array return StreamUtils.getBytes(arg); } """ Given url 'http://my-server/post' And def image = convertToBytes(read('classpath:images/image_1.jpg')); And request {id:1, data: "#(image)"}

How to get a value (ex: baseURL) in every Karate feature?

自作多情 提交于 2019-12-20 02:56:39
问题 I would like to get a common variable for all features. Ex: base URL and path (in some features). I don't understand well in Karate official tutos what to do exactly. I put in user.feature `Background: * url urlBase * path users In karate-config.js function() { var env = karate.env; karate.log('karate.env system property was:', env); if (!env) { env = 'dev'; } var config = { env: env, appId: 'my.app.id', appSecret: 'my.secret', baseURL: 'https://someurl/', users: 'users' }; karate.configure(

Pass Json to karate-config.js file

混江龙づ霸主 提交于 2019-12-18 07:21:41
问题 I have more than 6 environments against which i have to run the same set of rest api scripts. For that reason i have stored all that test data and the end points/resource paths in a json file. I then try to read this json file into my karate-config.js file, this is because i want to fetch the data corresponding to the environment that is being passed from the command line (karate.env), which am reading into my karate-config.js file Below is my json file sample [ { "qa":{ "username_cm_on":

How to put “OR” operator in Karate API assertion statement

故事扮演 提交于 2019-12-14 03:58:05
问题 I would like to use "OR" operator for assertion statement in Karate API. This is the first time I am trying to OR operator in Karate API: match response.items[0].type == 'Purchase' I would like to use an OR operator like: match response.items[0].type == 'Purchase' or 'Freeplay' I have not been able to successfully execute with or statement 回答1: Sometimes assert is the simplest option: * def itemType = response.items[0].type * assert (itemType == 'Purchase') || (itemType == 'Freeplay') There

Karate API - Assertion with fuzzy matching #number

半城伤御伤魂 提交于 2019-12-14 02:43:27
问题 path: $.ActiveScriptJobID, actual: '17124', expected: '#number', reason: not a number Above error message displays for below scenario Given path 'admin/rest/activescript/job/17124' When method get Then status 200 * match resp.ActiveScriptJobID == "#number" 回答1: You haven't provided the actual response so your question is incomplete. But check the JSON. It is sure to be a string (within quotes) not a number. Maybe you need to use a regex: https://github.com/intuit/karate#fuzzy-matching * match

When karate-config.js fails it prints error for each feature

a 夏天 提交于 2019-12-13 19:30:13
问题 Karate-Netty version 0.9.2 Whenever my karate-config.js evaluation fails it prints: 16:49:28.753 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - evaluation of 'karate-config.js' failed: javascript function call failed: unexpected 'configure' key: 'followRedirectss' 16:49:28.761 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - javascript function call failed: unexpected 'configure' key: 'followRedirectss' 16:49:28.762 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - failed function

how to make a copy of the result of a call

假装没事ソ 提交于 2019-12-13 18:17:04
问题 Why does the following test not pass? I must be missing something fundamental about how copy works. It seems to have a reference to the json object and not a copy. Feature: testing @one Scenario: one * def root = { name: 'inner' } Scenario: two * def a = call read('testing.feature@one') * copy b = a * set b.root.name = "copy" * match b.root.name == "copy" * match a.root.name == "called" 回答1: Always un-wrap the results of call . The reason is that particular JSON object is "special" (a Java

Is there a way to set variables in a scenario and use them in another scenario in karate framework?

∥☆過路亽.° 提交于 2019-12-13 18:09:42
问题 I get a value in the response by running one of the scenarios and I would like to use that value in the next scenario. Is there a way to set variables in the context of a feature with karate? I know I can call another feature from within the feaure, but I don't want to move that scenario in another feature and do the call. 回答1: Please note that having scenarios depend on another is considered a bad practice, and I don't recommend it: https://github.com/intuit/karate#script-structure But

How to get Child elements in Karate framework

喜你入骨 提交于 2019-12-13 18:08:49
问题 I need to extract child elements from response of one api and then pass it dynamically to next api request. Suppose i have the below xml: * def foo = """ <records> <record index="1">a</record> <record index="2">b</record> <record index="3" foo="bar">c</record> </records> """ I want to extract only this: <record index="1">a</record> <record index="2">b</record> <record index="3" foo="bar">c</record> I tried below options, but none of then worked: * def chk = foo//records/* * def chk = foo/