Skip to content

Instantly share code, notes, and snippets.

View ptrthomas's full-sized avatar

Peter Thomas ptrthomas

View GitHub Profile
@ptrthomas
ptrthomas / gist:920f8a42fac4ab0bb121a5ad74b09cdb
Created July 19, 2023 03:01 — forked from wmcu/gist:7dfc341f12c330618e47
Example of Jsch usage for SSH
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
import com.jcraft.jsch.*;
public class SSH {
public static void main(String[] args) {
System.out.println("Begin!");
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 / 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('[email protected]')
* rightOf('{}Password:').input('password1234')
Feature: person mock server
Background:
* def persons =
"""
{
'1': { id: 1, firstName: 'FN1', lastName: 'LN1', email: '[email protected]' },
'2': { id: 2, firstName: 'FN2', lastName: 'LN2', email: '[email protected]' },
'3': { id: 3, firstName: 'FN3', lastName: 'LN3', email: '[email protected]' },
'4': { id: 4, firstName: 'FN4', lastName: 'LN4', email: '[email protected]' }

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