Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
Last active January 11, 2021 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielplawgo/b7f647af83d1345e9bac532cc10c8cfb to your computer and use it in GitHub Desktop.
Save danielplawgo/b7f647af83d1345e9bac532cc10c8cfb to your computer and use it in GitHub Desktop.
Karate - automatyczne testy API
Feature: Auth - fetching jwt token
Background:
* url baseUrl+"/api/Auth/Login"
Scenario: Featch jwt token
Given request {"Username":"#(userName)","Password":"#(password)"}
When method POST
Then status 200
And match response contains { "message": "Success" }
* def token = response.token
java -jar karate.jar -t ~@ignore src
{
"baseUrl": "http://localhost:49705",
"userName": "daniel@plawgo.pl",
"password": "Password9."
}
Scenario: Login
Given url "run.cmd"
And request {"Username":"userName","Password":"password"}
When method POST
Then status 200
Feature: Get product
Background:
* url baseUrl+'/api/products/1'
Scenario: Get product with id equal 1
When method GET
Then status 200
And match response == {"id":1,"name":"Name-1"}
function() {
var config = karate.read('classpath:environment-config.json');
var authResult = karate.callSingle('classpath:src/Auth.feature',config);
karate.configure('headers', {
'Authorization': 'Bearer ' + authResult.token
});
return config;
}
curl -L https://github.com/intuit/karate/releases/download/v0.9.6/karate-0.9.6.jar --output karate.jar
java -jar karate.jar -t ~@ignore src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment