karate

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

拜拜、爱过 提交于 2019-12-01 23:23:02
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. Is there anyway to prevent Karate from adding it? The default setting of UTF-8 on Content-Type can be

Can we loop feature files and execute using multiple login users in karate

余生长醉 提交于 2019-12-01 22:54:28
For our project requirement we have to run the feature file using 50 users . For now I am able to run using one user which is configured in the karate.config file. I need to configure these 50 users in the config file and run the same feature file for all 50 users. Looking for a way to configure all users in one config file and run the feature file. Here's my suggestion. Don't overload your config file like this. Use a JSON file with an array of users. Now you can read this JSON file from any feature using the read syntax. And you can use Karate's built-in looping capability to do what you

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

不羁的心 提交于 2019-12-01 22:21:55
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('connectTimeout', 5000); karate.configure('readTimeout', 5000); return config; } and in my runner class:

[karate][standalone] Error : could not find or read file

两盒软妹~` 提交于 2019-12-01 22:06:40
问题 I am only using the latest standalone karate jar to test my API on a docker container configured with JRE and I don't have any Java code. Currently on one of my features, i have this : read('file.json') , and it works fine when the resource file is on the same directory than the feature file. I know that it is recommended to do this way. But if i also want to have a central directory with all resource files to avoid duplicatas, it doesn't work even with this command : read('classpath

How to call a particular javascript function from .js file in karate feature file

时光毁灭记忆、已成空白 提交于 2019-12-01 09:43:42
问题 Suppose I have saved followings functions in a Utility js file. function getCurrentDate(){ return 'date'; } function getMonth(){ return 'Oct'; } Please help me how any of these methods can be accessed in feature file. I tried following code but it is not working. * def fun = call read('Utility.js') * def result = getData() or * def result = fun.getData() 回答1: In Karate, a JS file can contain only one function and it does not need a name, take a closer look at the examples. I don't really

Karate karate-config.js not a js function

跟風遠走 提交于 2019-12-01 08:34:12
I'm trying use karate for e2e tests and have started with a minimal setup. I want to create some config items in karate-config.js for use in the tests but karate is reporting that file is not a js function and hence the test fails trying to get the config: Warning: Nashorn engine is planned to be removed from a future JDK release 12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null] --------------------------------------------------------- feature: classpath:karate/insurer.feature scenarios: 1 |

In the Karate DSL Framework, how can we add custom step definitions to expand its functionalities beyond REST capabilities?

允我心安 提交于 2019-11-30 20:09:51
问题 I understand the philosophy behind Karate is to not have to add custom Step definitions. However, the REST API Testing we perform in our project is more integrated so we have to verify POST responses in MongoDB collections, ActiveMQ, and a SQL Server DB. Is there anyway to easily add custom step definitions to expand the Karate DSL Framework beyond its REST Capabilities? I tried downloading the source code and importing it as a Maven project but I came across many dependency issues. 回答1: It

Is there a way to write to a text file using Karate

不问归期 提交于 2019-11-29 16:45:10
In my karate tests i need to write response id's to txt files (or any other file format such as JSON), was wondering if it has any capability to do this, I haven't seen otherwise in the documentation. In the case of no, is there a simple JavaScript function to do so? Try karate.write(value, filename) in JavaScript. We have kept this un-documented because we don't encourage it. Also the file will be written only to the current "build" directory which will be target for Maven projects / stand-alone JAR. value can be any data-type. Here is an example . EDIT: for others coming across this answer

Karate API Testing - Reusing variables in different scenarios in the same feature file

◇◆丶佛笑我妖孽 提交于 2019-11-29 15:45:29
Does Karate supports a feature where you can define a variable in a scenario and reuse it in other scenarios in the same feature file. I tried doing the same but get an error. What's the best way to reuse the variables within the same feature file ? Scenario: Get the request Id * url baseUrl Given path 'eam' When method get Then status 200 And def reqId = response.teams[0]resourceRequestId Scenario: Use the above generated Id * url baseUrl * print 'From the previous Scenario: ' + reqId Error: Caused by: javax.script.ScriptException: ReferenceError: "reqId" is not defined in <eval> at line

Pass Json to karate-config.js file

China☆狼群 提交于 2019-11-29 12:47:49
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":"test_cm_on_qa", "password_cm_on":"Test123$", "nonadmin_username_cm_on":"test_non_admin_cm_on_qa",