Skip to content

Commit

Permalink
more improvements to the headers demo example
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Sep 10, 2017
1 parent 573ef8e commit 31c8f28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions karate-demo/src/test/java/demo/headers/headers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion karate-demo/src/test/java/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down

0 comments on commit 31c8f28

Please sign in to comment.