karate

How can I send just 'application/json' as the content-type header with Karate?

最后都变了- 提交于 2019-12-02 05:55:26
问题 I'm trying to write my first test for a service that I have no control over. The service validates headers on incoming requests and for the content-type header it requires that the value be application/json , and only that value. However when I try to write a test and explicitly set the content-type header to only have this value, the header that is generated has the following value instead: application/json; charset=UTF-8 This additional charset=UTF-8 value is preventing my test from passing

want to test assertion of integer value should be >3 in Karate API

馋奶兔 提交于 2019-12-02 03:49:51
json response is "Value": 0.23 i want to put assertion here value should be less than 3 so how to do this ? tried some examples in documentation but they are for array format of jsonenter code here Scenario: Shows the minimum time any DB request to CS will take This value is an important indicator for the performance of the database access. Given path 'admin/rest/status/db/' When method get Then status 200 And match response contains { Value: ">3"} * match Value == { '#? _ > 3' } * match $.Value == '##[_ > 3]' * def H = response * print H tried with above assertion not found any solution You

How to test each date field in the array response using Karate

女生的网名这么多〃 提交于 2019-12-02 03:37:38
i have response like { Data: {a: [{ date1: "2018-12-23", date2: "23-11-2018" },{ date1: "2018-12-20",date2: "23-11-2018" }] } } and want to test if each date1 field is less than today's date and each date2 is less than input date field (i have a date field in input payload) How can i perform that. In many ways, here is one. Refactoring this code to be cleaner is homework for you :P * def toTime1 = """ function(s) { var SimpleDateFormat = Java.type('java.text.SimpleDateFormat'); var sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.parse(s).time } """ * def toTime2 = """ function(s) { var

Cannot escape url as needed

醉酒当歌 提交于 2019-12-02 02:47:12
I am tring to escape some values in a path. Let's say I'm trying to obtain https://www.google.com/https%3A%2F%2Fdomain I've tried the following options : Scenario: escape value * url "https://www.google.com" * path "https://domain" When method get * path "https\:\/\/domain" When method get * path "https%3A%2F%2Fdomain" When method get * path "https\\:\\/\\/domain" When method get But I obtain https://www.google.com/https://domain https://www.google.com/https://domain https://www.google.com/https%253A%252F%252Fdomain Why is \ not working, while %2F is being escaped into %252F ? Encoding is the

How to test download api using karate

删除回忆录丶 提交于 2019-12-02 02:46:51
问题 I have an api for file download ( txt, .doc,*.csv) using spring framework in java.i wanted to do acceptance testing using karate .how can i do that. here is my code @RequestMapping(path = "/download", method = RequestMethod.GET) public ResponseEntity<Resource> download(String param) throws IOException { InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); return ResponseEntity.ok() .headers(headers) .contentLength(file.length()) .contentType(MediaType

Passing defined variable through different scenarios is not working

为君一笑 提交于 2019-12-02 02:24:01
问题 Trying to pass a reference of the response of a POST scenario to another scenario with PATCH method and changing one of the properties and getting errors. Debbuging the source code i found that when Scripts.assign is called for one scenario, the variable scope doesn't pass to the another scenario. Karate version: 0.5.0 Java version: 1.8 Full feature of the test: Feature: Products CRUD Test Background: * url demoBaseUrl Scenario: fetch some products Given path 'products' When method get Then

How to test download api using karate

拟墨画扇 提交于 2019-12-02 02:15:54
I have an api for file download ( txt, .doc,*.csv) using spring framework in java.i wanted to do acceptance testing using karate .how can i do that. here is my code @RequestMapping(path = "/download", method = RequestMethod.GET) public ResponseEntity<Resource> download(String param) throws IOException { InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); return ResponseEntity.ok() .headers(headers) .contentLength(file.length()) .contentType(MediaType.parseMediaType("application/octet-stream")) .body(resource); } See line number 16 in this example upload.feature

Karate - How to import json data

99封情书 提交于 2019-12-02 01:46:53
I want to import some JSON data to my tests. In order to documentation I should do that like this: * def data = read('classpath:init/data.json') I've created my JSON file with this content: { "name": "ehsan" } This is my code: Background: * def data = call read('classpath:init/data.json') Scenario: * print data But it prints nothing and says: 16:11:30.898 [main] WARN com.intuit.karate - not a js function or feature file: read('classpath:init/data.json') - [type: JSON, value: com.jayway.jsonpath.internal.JsonContext@7d61eccf] Below code is correct: * def data = read('classpath:init/data.json')

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

前提是你 提交于 2019-12-02 01:14:55
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 data * def config = {username: 'postgres', password: 'postgres', url: 'jdbc:postgresql://localhost:5432

How to compare XML response with Json in Karate

偶尔善良 提交于 2019-12-02 00:41:07
I need to match and validate my JSON response with that of downstream XML response. Here are sample responses for both. Note that Json response parameters are is not in-order with XML response. JSON RESPONSE "Main": { "Cd": "ABC", "descriptionTxt": "Sample Main", "type": "A", "codeType": "P", "dt": "2018-10-15T00:00:00-05:00", "validity": "3", "segment": "Personal" }, "testList": [ { "code": "123", "descriptionTxt": "My Description", "categoryCd": "DUDU" }, { "code": "675", "descriptionTxt": "His Description" }, { "code": "345", "descriptionTxt": "Your Description", "categoryCd": "BH" } ] XML