Skip to content

Instantly share code, notes, and snippets.

View ptrthomas's full-sized avatar

Peter Thomas ptrthomas

View GitHub Profile
@ptrthomas
ptrthomas / multi-set.feature
Last active September 20, 2017 05:47
Karate's set via table approach for payload building: https://github.com/intuit/karate#set-multiple
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 / consumer-provider-example-table.md
Last active January 7, 2018 06:44
Consumer-Provider Example
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
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' }
@ptrthomas
ptrthomas / karate-answers2.feature
Last active January 27, 2019 14:04
Karate example that replaces the combination of REST-Assured and TestNG data-provider | https://bit.ly/2G4qvBe
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>'
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;
@ptrthomas
ptrthomas / karate-dependencies.txt
Last active July 18, 2021 14:20
The maven dependencies needed for a vanilla karate project
[INFO] \- com.intuit.karate:karate-core:jar:1.1.0.RC4:test
[INFO] +- org.graalvm.js:js-scriptengine:jar:21.1.0:test
[INFO] | \- org.graalvm.sdk:graal-sdk:jar:21.1.0:test
[INFO] +- org.graalvm.js:js:jar:21.1.0:test
[INFO] | +- org.graalvm.regex:regex:jar:21.1.0:test
[INFO] | +- org.graalvm.truffle:truffle-api:jar:21.1.0:test
[INFO] | \- com.ibm.icu:icu4j:jar:68.2:test
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:test
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:test
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:test
@ptrthomas
ptrthomas / customer-manager.feature
Last active August 12, 2021 09:53
Karate vs Taiko
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')
@ptrthomas
ptrthomas / json-contains.feature
Last active October 19, 2021 21:41
Karate and JSON `contains`
Given def cat =
"""
{
name: 'Billie',
kittens: [
{ id: 23, name: 'Bob' },
{ id: 42, name: 'Wild' }
]
}
"""
@ptrthomas
ptrthomas / hello-world.feature
Created April 2, 2017 06:15
Karate Hello World
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

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' }