karate

Karate get one variable from a request

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:41:09
问题 Given request """ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.openkm.com"> <soapenv:Header/> <soapenv:Body> <ws:login> <!--Optional:--> <user>TestUser</user> <!--Optional:--> <password>TestUser</password> </ws:login> </soapenv:Body> </soapenv:Envelope> """ When soap action 'http://ws.openkm.com/OKMAuth/login' Then status 200 * def token = //return Result = response={soap:Envelope={ ={soap:Body={ns2:loginResponse={ =‌​ {return=a866fb4f-47e‌​4

Log name of Scenario when it starts

我的未来我决定 提交于 2019-12-11 07:27:45
问题 Is there a way to get Karate to automatically print the name of each scenario as it is executed into the logs? We have a reasonably large suite that generates ~25MB of log data in our Jenkins pipeline console output and sometimes it’s a little tricky trying to match a line where com.intuit.karate logs an ERROR to the failure summary at the end of the run. It is most likely possible to obtain the scenario name and print() it but that would mean adding code to many hundred scenarios which I’d

Karate - Database testing - getting timestamp displayed as nano

孤者浪人 提交于 2019-12-11 07:06:45
问题 I am trying to run some basic database tests using Karate and Spring JDBC ( as mentioned in DBUtils class in Demo Project). Here is what I am doing: Background: # Read url/username/pwd and provide it to the class * def config = read('env_file.json') * def DbUtils = Java.type('DbConnection') * def db = new DbUtils(config) Scenario: Validate the modd_ts is present in lob table * def createdTs = db.readRows('SELECT crtd_ts FROM tableA ') * print createdTs Here is what it returns: com.intuit

Invoke filed from last scenario response failed with karate

百般思念 提交于 2019-12-11 06:59:46
问题 Below is my code, i want to use CartItemId from scenario1 response as request for scenario2, but scenario cannot get its value. Scenario: /api/wishlist/item/add - add to wishlist Given path '/api/wishlist/item/add' And headers allHeaders.HeadersToken And request {"CultureCode":"CHS","IsSpecificSku":0,"MerchantId":"#(data.StyleMerchantId)","SkuId":"#(data.SkuId)","UserKey":"#(data.UserKey)"} When method POST Then status 200 * def CartItemId = response.CartItems[0].CartItemId * print CartItemId

Schema validation: string from specific list of values

前提是你 提交于 2019-12-11 06:47:47
问题 I have an endpoint with the following response: { "id": 1, "status": "ACTIVE" } The possible values for status are the following: ACTIVE, INACTIVE, DELETED. To check the schema I tried the following: * def statusValues = ["ACTIVE", "INACTIVE", "DELETED" ] * def schema = """ { "id" : #number, "status" : '#(^*statusValues)' } """ And to validate I use the following sentence: Then match response == schema But it doesn't work. This is the error actual: 'ACTIVE', expected: ["DELETED","ACTIVE",

Properly calling an authorization Karate feature with arguments

风格不统一 提交于 2019-12-11 06:37:21
问题 I have an authentication feature working, but would like to make it reusable. I'm not able to get working through the methods I've tried so far. The standalone method that works is: # Created at 10/4/18 Feature: #Authentication Management Background: * url gatewayUrl * def myid = 'myid' * def mysecret = 'mysecret' Scenario: # Generate authentication token for x user Given path 'mypath' And header Content-Type = 'application/x-www-form-urlencoded' And request 'grant_type=api_key&myid=' + myid

How to get id in responseHeaders location?

眉间皱痕 提交于 2019-12-11 06:30:12
问题 For my POST request, in responseHeaders I get 1 < location: /users/123 I would like to print only the id > 123. When I do * print responseHeaders['location'][0] in my feature file, I get users/123 . How I can get only the id? 回答1: This is not really a Karate question is it :P Try this: * def location = responseHeaders['location'][0] * def userId = location.substring(location.lastIndexOf('/') + 1) * print userId That's right, all the power of JavaScript (or even Java via Java interop) is

embedded expression not replaced properly in the complex json

梦想的初衷 提交于 2019-12-11 06:17:47
问题 In a Karate test - we are able to replace embedded expression for single key in a json. but when trying to replace in complex key of the json it is not working input json: { "integration": { "serviceData": { "integrationService": { "name": "#(integrationName)", "description": "#(tenantID)", "serviceData": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n <block type=\"start_block\" id=\"foOIiCF5aZGnie1GzBDB\" deletable=\"false\" x=\"150\" y=\"25\">\n <field name=\"ORCH_NAME\">Add2NumDocInputs<

How to use a variable in JsonPath filter

旧城冷巷雨未停 提交于 2019-12-11 06:17:07
问题 I'm attempting to use a variable in the RHS of an JsonPath filter expression in a Karate test, similar to this: * def name = 'A Name' * def ids = $response[?(@.name == '#(name)')].id If I use the literal string 'A Name' in the RHS of the expression it works as expected. I've tried various ways to get the variable to evaluate: '<name>' , "#(name)" , etc. I suspect it is because I'm mixing JsonPath parsing with Karate parsing perhaps? 回答1: Read this first: https://github.com/intuit/karate#rules

Folder specific cucumber-reporting without parallel run?

∥☆過路亽.° 提交于 2019-12-11 06:09:16
问题 Was wondering if I could get setup cucumber-reporting for specific folders? For example in the https://github.com/intuit/karate#naming-conventions, in CatsRunner.java i set up the third party cucumber reporting? without parallel execution. please advise or direct me on how to set it up. Rationale. its easier to read and helps me in debugging 回答1: You are always recommended to use the 3rd party Cucumber Reporting when you want HTML reports. And you can create as many Java classes similar to