Skip to content

Instantly share code, notes, and snippets.

View ping.feature
Feature:
Scenario: listen to system out and stop after 5 pings
* def count = 0
* def listener =
"""
function(line) {
var temp = karate.get('count');
if (line.contains('bytes from')) {
temp = temp + 1;
View customer-manager.feature
Feature: customer manager
Background:
* driver 'http://localhost:3000'
Scenario:
* match driver.title == 'Angular TypeScript JumpStart App'
* click('{}Login')
* rightOf('{}Email:').input('admin@customermanager.com')
* rightOf('{}Password:').input('password1234')
View person-mock.feature
Feature: person mock server
Background:
* def persons =
"""
{
'1': { id: 1, firstName: 'FN1', lastName: 'LN1', email: 'email1@email.com' },
'2': { id: 2, firstName: 'FN2', lastName: 'LN2', email: 'email2@email.com' },
'3': { id: 3, firstName: 'FN3', lastName: 'LN3', email: 'email3@email.com' },
'4': { id: 4, firstName: 'FN4', lastName: 'LN4', email: 'email4@email.com' }
View karate-json-assertions.md

refer to this for a working example: schema-like.feature

* def actual = [{ a: 1, b: 'x' }, { a: 2, b: 'y' }]

* def schema = { a: '#number', b: '#string' }
* def partSchema = { a: '#number' }
* def badSchema = { c: '#boolean' }
* def mixSchema = { a: '#number', c: '#boolean' }
View consumer-provider-example-table.md
Ref Source Code Description
C Consumer.java The 'consumer' or client application that consumes the demo 'Payment Service' and also listens to a queue
P PaymentService.java The provider 'Payment Service' implemented in Spring Boot and using an in-memory data-store
1 ConsumerIntegrationTest.java An end-to-end integration test of the consumer that needs the real provider to be up and running
KC payment-service.feature A 'normal' Karate functional-test that tests the 'contract' of the Payment Service fro
@ptrthomas
ptrthomas / karate-dependencies.txt
Last active Jun 27, 2019
The maven dependencies needed for a vanilla karate project using the Apache HTTP client
View karate-dependencies.txt
[INFO] +- com.intuit.karate:karate-apache:jar:0.9.3:test
[INFO] | +- com.intuit.karate:karate-core:jar:0.9.3:test
[INFO] | | +- com.jayway.jsonpath:json-path:jar:2.1.0:test
[INFO] | | | \- net.minidev:json-smart:jar:2.2:test
[INFO] | | | \- net.minidev:accessors-smart:jar:1.1:test
[INFO] | | | \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] | | +- info.cukes:cucumber-java:jar:1.2.5:test
[INFO] | | | \- info.cukes:cucumber-core:jar:1.2.5:test
[INFO] | | +- org.yaml:snakeyaml:jar:1.24:test
[INFO] | | +- de.siegmar:fastcsv:jar:1.0.3:test
@ptrthomas
ptrthomas / multi-set.feature
Last active Sep 20, 2017
Karate's set via table approach for payload building: https://github.com/intuit/karate#set-multiple
View multi-set.feature
Scenario: set via table where variable does not exist
note how karate will create parent paths if needed
* set foo
| path | value |
| bar | 'baz' |
| a.b | 'c' |
| fizz | { d: 'e' } |
* match foo == { bar: 'baz', a: { b: 'c' }, fizz: { d: 'e' } }
@ptrthomas
ptrthomas / json-contains.feature
Last active Apr 2, 2017
Karate and JSON `contains`
View json-contains.feature
Given def cat =
"""
{
name: 'Billie',
kittens: [
{ id: 23, name: 'Bob' },
{ id: 42, name: 'Wild' }
]
}
"""
View hello-world.feature
Feature: karate 'hello world' example
Scenario: create and retrieve a cat
Given url 'http://myhost.com/v1/cats'
And request { name: 'Billie' }
When method post
Then status 201
And match response == { id: '#notnull', name: 'Billie' }
Given path response.id
@ptrthomas
ptrthomas / karate-answers2.feature
Last active Jan 27, 2019
Karate example that replaces the combination of REST-Assured and TestNG data-provider | https://bit.ly/2G4qvBe
View karate-answers2.feature
Feature: karate answers 2
Background:
* url 'http://localhost:8080'
Scenario Outline: given circuit name, validate country
Given path 'api/f1/circuits/<name>.json'
When method get
Then match $.MRData.CircuitTable.Circuits[0].Location.country == '<country>'