From 31c8f28804436235271158a833ccb6eb74a24211 Mon Sep 17 00:00:00 2001 From: Peter Thomas Date: Sun, 10 Sep 2017 19:59:44 +0530 Subject: [PATCH] more improvements to the headers demo example --- karate-demo/src/test/java/demo/headers/headers.feature | 3 +++ karate-demo/src/test/java/headers.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/karate-demo/src/test/java/demo/headers/headers.feature b/karate-demo/src/test/java/demo/headers/headers.feature index 6d0f31633..d3bdb9675 100644 --- a/karate-demo/src/test/java/demo/headers/headers.feature +++ b/karate-demo/src/test/java/demo/headers/headers.feature @@ -23,6 +23,9 @@ Background: And match responseCookies !contains { blah: '#notnull' } Scenario: configure function + this is the approach that most projects would use, especially if some header needs + to be dynamic for each request. for e.g. see how a 'request_id' header is set in 'headers.js' + * configure headers = read('classpath:headers.js') Given path 'headers', token And param url = demoBaseUrl diff --git a/karate-demo/src/test/java/headers.js b/karate-demo/src/test/java/headers.js index d990f6a39..cefa3ec2b 100644 --- a/karate-demo/src/test/java/headers.js +++ b/karate-demo/src/test/java/headers.js @@ -2,9 +2,13 @@ function() { var token = karate.get('token'); var time = karate.get('time'); if (token && time) { + var uuid = java.util.UUID.randomUUID(); // create a unique id for each request // demoBaseUrl was available at the time this function was declared // and so behaves like a constant, use 'karate.get' for dynamic values - return { Authorization: token + time + demoBaseUrl }; + return { + Authorization: token + time + demoBaseUrl, + request_id: uuid + }; } else { return {}; }