├── kafka-mtls
├── ssl
│ ├── creds_sslkey
│ ├── ca.srl
│ ├── creds_keystore
│ ├── server.p12
│ ├── server.keystore.pkcs12
│ ├── client.truststore.pkcs12
│ ├── server.csr
│ ├── ca.crt
│ ├── server.crt
│ ├── ca.key
│ ├── server.key
│ └── ca.pem
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── mock.feature
│ │ ├── AllRunner.java
│ │ ├── KafkaJsonTest.java
│ │ ├── KafkaHybridTest.java
│ │ ├── kafka-json.feature
│ │ ├── KafkaUtils.java
│ │ └── kafka-hybrid.feature
│ │ └── logback-test.xml
├── conf
│ ├── ca.cnf
│ ├── server.cnf
│ └── commands.txt
├── docker-compose.yml
├── README.md
└── pom.xml
├── kafka
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── hello-common.proto
│ │ ├── hello.proto
│ │ ├── complex.json
│ │ ├── AllRunner.java
│ │ ├── KafkaTest.java
│ │ ├── KafkaJsonTest.java
│ │ ├── KafkaMultiTest.java
│ │ ├── KafkaProtoTest.java
│ │ ├── hello.avsc
│ │ ├── kafka-json.feature
│ │ ├── kafka-proto.feature
│ │ ├── kafka.feature
│ │ ├── complex.avsc
│ │ └── kafka-multi.feature
│ │ └── logback-test.xml
├── docker-compose.yml
├── README.md
└── pom.xml
├── quarkus
├── src
│ ├── test
│ │ └── java
│ │ │ ├── application.properties
│ │ │ ├── karate-config.js
│ │ │ ├── karate
│ │ │ ├── greeting.feature
│ │ │ └── GreetingTest.java
│ │ │ └── logback-test.xml
│ └── main
│ │ └── java
│ │ └── io
│ │ └── karatelabs
│ │ └── examples
│ │ └── quarkus
│ │ ├── GreetingService.java
│ │ └── GreetingResource.java
├── README.md
└── pom.xml
├── websocket
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── echo.feature
│ │ ├── json.feature
│ │ ├── EchoTest.java
│ │ ├── JsonRunner.java
│ │ ├── StompRunner.java
│ │ ├── stomp.feature
│ │ └── StompAdapter.java
│ │ └── logback-test.xml
├── pom.xml
└── README.md
├── database
├── src
│ ├── test
│ │ └── java
│ │ │ ├── schema.sql
│ │ │ ├── application.properties
│ │ │ ├── karate-config.js
│ │ │ ├── logback-test.xml
│ │ │ └── karate
│ │ │ ├── dogs.feature
│ │ │ ├── DogsTest.java
│ │ │ └── DbUtils.java
│ └── main
│ │ └── java
│ │ └── io
│ │ └── karatelabs
│ │ └── examples
│ │ └── database
│ │ ├── Application.java
│ │ ├── Dog.java
│ │ └── DogsController.java
├── README.md
└── pom.xml
├── ssh
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── ssh.feature
│ │ ├── SshTest.java
│ │ └── SshSession.java
│ │ └── logback-test.xml
├── README.md
└── pom.xml
├── grpc
├── src
│ ├── test
│ │ └── java
│ │ │ ├── karate-config.js
│ │ │ ├── karate
│ │ │ ├── hello.proto
│ │ │ ├── hello-tls.feature
│ │ │ ├── hello-tls-mutual.feature
│ │ │ ├── HelloTest.java
│ │ │ ├── HelloTlsTest.java
│ │ │ ├── HelloTlsMutualTest.java
│ │ │ └── hello.feature
│ │ │ ├── logback-test.xml
│ │ │ ├── io
│ │ │ └── karatelabs
│ │ │ │ └── examples
│ │ │ │ └── grpc
│ │ │ │ └── HelloJavaRunner.java
│ │ │ ├── client.crt
│ │ │ ├── server.crt
│ │ │ ├── ca.crt
│ │ │ ├── crypto.txt
│ │ │ ├── client.pem
│ │ │ └── server.pem
│ └── main
│ │ └── proto
│ │ └── hello.proto
└── README.md
├── micronaut
├── src
│ ├── test
│ │ └── java
│ │ │ ├── application-test.yml
│ │ │ ├── karate-config.js
│ │ │ ├── karate
│ │ │ ├── hello.feature
│ │ │ └── HelloTest.java
│ │ │ └── logback-test.xml
│ └── main
│ │ ├── resources
│ │ ├── application.yml
│ │ └── logback.xml
│ │ └── java
│ │ └── io
│ │ └── karatelabs
│ │ └── examples
│ │ ├── Application.java
│ │ └── HelloController.java
├── README.md
└── pom.xml
├── .gitignore
├── grpc-custom
├── src
│ ├── test
│ │ └── java
│ │ │ ├── karate-config.js
│ │ │ ├── karate
│ │ │ ├── grpc.feature
│ │ │ ├── GrpcTest.java
│ │ │ ├── GrpcJavaTest.java
│ │ │ ├── grpc-java.feature
│ │ │ └── GrpcUtils.java
│ │ │ ├── io
│ │ │ └── karatelabs
│ │ │ │ └── examples
│ │ │ │ └── grpc
│ │ │ │ └── HelloTest.java
│ │ │ └── logback-test.xml
│ └── main
│ │ ├── proto
│ │ └── hello.proto
│ │ └── java
│ │ └── io
│ │ └── karatelabs
│ │ └── examples
│ │ └── grpc
│ │ ├── HelloServer.java
│ │ └── HelloClient.java
└── README.md
├── jbang-npm
├── test.js
├── package.json
├── Hello.java
└── javaTest.feature
├── ssl
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── server-keystore.p12
│ │ └── java
│ │ │ └── io
│ │ │ └── karatelabs
│ │ │ └── examples
│ │ │ └── ssl
│ │ │ └── TestService.java
│ └── test
│ │ └── java
│ │ ├── ssl
│ │ ├── SslRunner.java
│ │ ├── ssl-truststore.feature
│ │ ├── SslTest.java
│ │ └── ssl-keystore.feature
│ │ └── logback-test.xml
├── README.md
└── pom.xml
├── rabbitmq
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── rabbitmq.feature
│ │ ├── RmqTest.java
│ │ └── RMQUtils.java
│ │ ├── logback-test.xml
│ │ └── io
│ │ └── karatelabs
│ │ └── examples
│ │ └── rabbitMQ
│ │ ├── KarateRMQRunner.java
│ │ ├── KarateRMQProducer.java
│ │ └── KarateRMQConsumer.java
├── docker-compose.yml
├── README.md
└── pom.xml
├── docker
├── Dockerfile
├── src
│ └── test.feature
└── README.md
├── kafka-custom
├── src
│ └── test
│ │ └── java
│ │ ├── karate-config.js
│ │ ├── karate
│ │ ├── kafka.feature
│ │ ├── KafkaTest.java
│ │ ├── hello.avsc
│ │ └── KafkaUtils.java
│ │ ├── io
│ │ └── karatelabs
│ │ │ └── examples
│ │ │ └── kafka
│ │ │ ├── AvroUtilsRunner.java
│ │ │ ├── KarateKafkaRunner.java
│ │ │ ├── AvroUtils.java
│ │ │ ├── KarateKafkaProducer.java
│ │ │ └── KarateKafkaConsumer.java
│ │ └── logback-test.xml
├── docker-compose.yml
├── README.md
└── pom.xml
├── aws-dynamodb
├── src
│ └── test
│ │ └── java
│ │ ├── karate
│ │ ├── dynamo-db.feature
│ │ └── DynamoDbTest.java
│ │ ├── logback-test.xml
│ │ └── examples
│ │ └── DynamoDbUtils.java
├── README.md
└── pom.xml
├── aws
└── README.md
├── jbang
├── karate.java
├── test.feature
└── README.md
├── slack
└── README.md
├── axe
└── README.md
├── cli
└── README.md
├── browserstack
├── browserstack.feature
└── README.md
├── lambdatest
├── lambdatest.feature
└── README.md
├── saucelabs
├── saucelabs.feature
└── README.md
├── LICENSE
└── spring-boot
└── README.md
/kafka-mtls/ssl/creds_sslkey:
--------------------------------------------------------------------------------
1 | karate
2 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/ca.srl:
--------------------------------------------------------------------------------
1 | C711566EEFF43565
2 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/creds_keystore:
--------------------------------------------------------------------------------
1 | karate
2 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 |
3 | }
4 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 |
3 | }
4 |
--------------------------------------------------------------------------------
/quarkus/src/test/java/application.properties:
--------------------------------------------------------------------------------
1 | quarkus.http.test-port=0
2 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 |
3 | }
4 |
--------------------------------------------------------------------------------
/database/src/test/java/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE DOGS (ID INT, NAME VARCHAR(50));
--------------------------------------------------------------------------------
/ssh/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | return {};
3 | }
4 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | return {};
3 | }
4 |
--------------------------------------------------------------------------------
/micronaut/src/test/java/application-test.yml:
--------------------------------------------------------------------------------
1 | server:
2 | host: localhost
3 | port: -1
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | target/
3 | .idea/
4 | .vscode/
5 | .karate/
6 | node_modules/
7 | package-lock.json
8 |
--------------------------------------------------------------------------------
/database/src/test/java/application.properties:
--------------------------------------------------------------------------------
1 | server.port=0
2 | spring.datasource.generate-unique-name=false
3 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/server.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karatelabs/karate-examples/HEAD/kafka-mtls/ssl/server.p12
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/hello-common.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | message Sender {
4 | string name = 1;
5 | }
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | return { Grpc: Java.type('karate.GrpcUtils') };
3 | }
4 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/server.keystore.pkcs12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karatelabs/karate-examples/HEAD/kafka-mtls/ssl/server.keystore.pkcs12
--------------------------------------------------------------------------------
/micronaut/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | return {
3 | urlBase: karate.properties['url.base']
4 | };
5 | }
6 |
--------------------------------------------------------------------------------
/quarkus/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | return {
3 | urlBase: karate.properties['url.base']
4 | };
5 | }
6 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/client.truststore.pkcs12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karatelabs/karate-examples/HEAD/kafka-mtls/ssl/client.truststore.pkcs12
--------------------------------------------------------------------------------
/jbang-npm/test.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 | const karate = require('@karatelabs/karate');
3 | karate.jvm.args = `Hello.java`
4 | karate.exec();
5 |
--------------------------------------------------------------------------------
/ssl/src/main/resources/server-keystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/karatelabs/karate-examples/HEAD/ssl/src/main/resources/server-keystore.p12
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | var Rmq = Java.type('karate.RmqUtils');
3 | return { rmq: new Rmq('my-queue') };
4 | }
5 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM eclipse-temurin:17-jre
2 |
3 | RUN curl -L -o karate.jar https://github.com/karatelabs/karate/releases/download/v1.5.0/karate-1.5.0.jar
4 |
--------------------------------------------------------------------------------
/micronaut/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | micronaut:
2 | application:
3 | name: default
4 | netty:
5 | default:
6 | allocator:
7 | max-order: 3
8 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | var KafkaUtils = Java.type('karate.KafkaUtils');
3 | return { kafka: new KafkaUtils('test-topic') };
4 | }
5 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/mock.feature:
--------------------------------------------------------------------------------
1 | @ignore
2 | Feature:
3 |
4 | Background:
5 | * def KafkaUtils = Java.type('karate.KafkaUtils')
6 |
7 | Scenario:
8 | * KafkaUtils.send()
9 | * def response = { success: true }
10 |
--------------------------------------------------------------------------------
/jbang-npm/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "test": "node test.js"
4 | },
5 | "devDependencies": {
6 | "@karatelabs/karate": "^0.2.2"
7 | },
8 | "dependencies": {
9 | "karate": "^1.0.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/hello.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | import "hello-common.proto";
4 |
5 | message Hello {
6 | string message = 1;
7 | Sender sender = 2;
8 | }
9 |
10 | message Another {
11 | string foo = 1;
12 | }
--------------------------------------------------------------------------------
/micronaut/src/test/java/karate/hello.feature:
--------------------------------------------------------------------------------
1 | Feature: micronaut integration test
2 |
3 | Background:
4 | * url urlBase
5 |
6 | Scenario: hello endpoint
7 | * path 'hello'
8 | * method get
9 | * status 200
10 | * match response == 'hello world'
11 |
--------------------------------------------------------------------------------
/aws-dynamodb/src/test/java/karate/dynamo-db.feature:
--------------------------------------------------------------------------------
1 | Feature:
2 |
3 | Scenario:
4 | * def Utils = Java.type('examples.DynamoDbUtils')
5 | * def db = new Utils()
6 | * def result = db.getItem('myKeyValue')
7 | * match result == { myFieldName: '#string' }
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate/grpc.feature:
--------------------------------------------------------------------------------
1 | Feature: example of using helper classes so that your karate tests
2 | can focus only on the calls, requests and responses
3 | look at karate-config.js for how "Grpc" was initialized
4 |
5 | Scenario:
6 | * match Grpc.hello('world') == 'hello world'
7 |
--------------------------------------------------------------------------------
/ssh/src/test/java/karate/ssh.feature:
--------------------------------------------------------------------------------
1 | Feature:
2 |
3 | Scenario:
4 | * def config = { user: 'ec2-user', host: '', privateKey: '' }
5 | * def SshSession = Java.type('karate.SshSession')
6 | * def ssh = new SshSession(config)
7 | * ssh.input('pwd')
8 | * ssh.input('whoami')
9 | * ssh.input('exit')
10 |
--------------------------------------------------------------------------------
/aws/README.md:
--------------------------------------------------------------------------------
1 | # Karate and AWS
2 |
3 | Any AWS service can be integrated into a Karate test using the [AWS Java SDK](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html) and [Java Interop](https://github.com/karatelabs/karate#calling-java).
4 |
5 | * [AWS DynamoDB](../aws-dynamodb/README.md)
--------------------------------------------------------------------------------
/jbang/karate.java:
--------------------------------------------------------------------------------
1 | ///usr/bin/env jbang "$0" "$@" ; exit $?
2 | //DEPS com.intuit.karate:karate-core:1.4.1:all
3 | //DEPS com.github.javafaker:javafaker:1.0.2
4 |
5 | public class karate {
6 |
7 | public static void main(String[] args) {
8 | com.intuit.karate.Main.main(args);
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/slack/README.md:
--------------------------------------------------------------------------------
1 | # Karate and Slack
2 |
3 | Refer to this [blog-post](https://medium.com/@markhughes321/integrate-karate-dsl-cucumber-reports-into-your-slack-channel-f6b4f7d71d08) and [sample code](https://github.com/markhughes321/karate-slack-integration) by [Mark Hughes](https://www.linkedin.com/in/markhughes321/).
--------------------------------------------------------------------------------
/micronaut/src/main/java/io/karatelabs/examples/Application.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples;
2 |
3 | import io.micronaut.runtime.Micronaut;
4 |
5 | public class Application {
6 |
7 | public static void main(String[] args) {
8 | Micronaut.run(Application.class, args);
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/jbang/test.feature:
--------------------------------------------------------------------------------
1 | Feature:
2 |
3 | Background:
4 | * def faker = new com.github.javafaker.Faker()
5 |
6 | Scenario:
7 | * def name = faker.name().fullName()
8 |
9 | * url 'https://httpbin.org/post'
10 | * request { name: '#(name)' }
11 | * method post
12 | * status 200
13 | * match response.json.name == name
14 |
--------------------------------------------------------------------------------
/jbang-npm/Hello.java:
--------------------------------------------------------------------------------
1 | ///usr/bin/env jbang "$0" "$@" ; exit $?
2 | //DEPS com.intuit.karate:karate-core:1.4.1:all
3 | //DEPS com.github.javafaker:javafaker:1.0.2
4 |
5 | class Hello {
6 |
7 | public static void main(String[] args) throws Exception {
8 | com.intuit.karate.Main.main(args);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/quarkus/src/main/java/io/karatelabs/examples/quarkus/GreetingService.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.quarkus;
2 |
3 | import jakarta.enterprise.context.ApplicationScoped;
4 |
5 | @ApplicationScoped
6 | public class GreetingService {
7 |
8 | public String greeting(String name) {
9 | return "hello " + name;
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/karate/rabbitmq.feature:
--------------------------------------------------------------------------------
1 | Feature: example of using helper classes so that your karate tests
2 | can focus only on the calls, requests and responses
3 | look at karate-config.js for how "rmq" was initialized
4 |
5 | Scenario:
6 | * rmq.send('hello world')
7 | * def result = rmq.listen()
8 | * match result == ['hello world']
9 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/echo.feature:
--------------------------------------------------------------------------------
1 | Feature: demo plain-text
2 |
3 | Scenario:
4 | * def session = karate.channel('websocket')
5 | * session.url = 'wss://ws.postman-echo.com/raw'
6 | * session.start()
7 |
8 | * session.send('hello')
9 |
10 | * def response = session.collect()
11 | * match response == ['hello']
12 |
--------------------------------------------------------------------------------
/grpc-custom/src/main/proto/hello.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | option java_multiple_files = true;
4 | option java_package = "io.karatelabs.examples.grpc";
5 |
6 | service HelloService {
7 | rpc Hello (HelloRequest) returns (HelloReply) {}
8 | }
9 |
10 | message HelloRequest {
11 | string name = 1;
12 | }
13 |
14 | message HelloReply {
15 | string message = 1;
16 | }
--------------------------------------------------------------------------------
/quarkus/src/test/java/karate/greeting.feature:
--------------------------------------------------------------------------------
1 | Feature: quarkus integration test
2 |
3 | Background:
4 | * url urlBase
5 |
6 | Scenario: hello endpoint
7 | * path 'hello'
8 | * method get
9 | * status 200
10 | * match response == 'hello'
11 |
12 | Scenario: greeting endpoint
13 | * path 'hello', 'greeting', 'world'
14 | * method get
15 | * status 200
16 | * match response == 'hello world'
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/complex.json:
--------------------------------------------------------------------------------
1 | {
2 | "meta": {
3 | "metaId": "123",
4 | "metaType": "AAA",
5 | "metaChildren": [{ "name": "foo", "status": "ONE" }]
6 | },
7 | "payload": {
8 | "payloadId": "456",
9 | "payloadType": null,
10 | "payloadEnum": "FIRST",
11 | "payloadChild": {"field1": "foo", "field2": "bar"}
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/ssl/src/test/java/ssl/SslRunner.java:
--------------------------------------------------------------------------------
1 | package ssl;
2 |
3 | import com.intuit.karate.junit5.Karate;
4 |
5 | class SslRunner {
6 |
7 | @Karate.Test
8 | Karate testKeystore() {
9 | return Karate.run("classpath:ssl/ssl-keystore.feature");
10 | }
11 |
12 | @Karate.Test
13 | Karate testTruststore() {
14 | return Karate.run("classpath:ssl/ssl-truststore.feature");
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/karate/kafka.feature:
--------------------------------------------------------------------------------
1 | Feature: example of using helper classes so that your karate tests
2 | can focus only on the calls, requests and responses
3 | look at karate-config.js for how "kafka" was initialized
4 |
5 | Scenario:
6 | * kafka.send({ message: 'hello', info: { first: 5, second: true } })
7 | * def result = kafka.listen()
8 | * match result == [{ message: 'hello', info: { first: 5, second: true } }]
9 |
--------------------------------------------------------------------------------
/database/src/test/java/karate-config.js:
--------------------------------------------------------------------------------
1 | function fn() {
2 | var DbUtils = Java.type('karate.DbUtils');
3 | var dbConfig = {
4 | url: 'jdbc:h2:mem:testdb',
5 | username: 'sa',
6 | password: '',
7 | driverClassName: 'org.h2.Driver'
8 | };
9 | var serverPort = karate.properties['server.port'];
10 | return {
11 | urlBase: 'http://localhost:' + serverPort,
12 | db: new DbUtils(dbConfig)
13 | };
14 | }
15 |
--------------------------------------------------------------------------------
/jbang-npm/javaTest.feature:
--------------------------------------------------------------------------------
1 | Feature: Example of NPM usage of Java library in Karate feature file.
2 |
3 | Background:
4 | * def faker = new com.github.javafaker.Faker()
5 |
6 | Scenario:
7 | * def name = faker.name().fullName()
8 |
9 | Given url 'https://httpbin.org/post'
10 | And request { name: '#(name)' }
11 | When method post
12 | Then status 200
13 | And match response.json.name == name
14 |
--------------------------------------------------------------------------------
/database/src/main/java/io/karatelabs/examples/database/Application.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.database;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Application.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/rabbitmq/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.2"
2 | services:
3 | rabbitmq:
4 | image: rabbitmq:3-management-alpine
5 | container_name: 'rabbitmq'
6 | ports:
7 | - 5672:5672
8 | - 15672:15672
9 | volumes:
10 | - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
11 | - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
12 | networks:
13 | - rabbitmq_go_net
14 |
15 | networks:
16 | rabbitmq_go_net:
17 | driver: bridge
18 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/hello.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | service HelloService {
4 | rpc Hello (HelloRequest) returns (HelloReply) {}
5 | rpc LotsOfReplies (HelloRequest) returns (stream HelloReply) {}
6 | rpc LotsOfGreetings (stream HelloRequest) returns (HelloReply) {}
7 | rpc BidiHello (stream HelloRequest) returns (stream HelloReply) {}
8 | }
9 |
10 | message HelloRequest {
11 | string name = 1;
12 | }
13 |
14 | message HelloReply {
15 | string message = 1;
16 | }
--------------------------------------------------------------------------------
/ssl/src/test/java/ssl/ssl-truststore.feature:
--------------------------------------------------------------------------------
1 | Feature: ssl with trust store / cert
2 |
3 | Background:
4 | * configure ssl =
5 | """
6 | {
7 | trustStore: 'classpath:server-keystore.p12',
8 | trustStorePassword: 'karate-mock',
9 | trustStoreType: 'pkcs12'
10 | }
11 | """
12 | * url 'https://localhost:8080'
13 |
14 | Scenario:
15 | * path 'test'
16 | * method get
17 | * status 200
18 | * match response == { success: true }
19 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/json.feature:
--------------------------------------------------------------------------------
1 | Feature: demo auto-conversion to json
2 |
3 | Scenario:
4 | * def session = karate.channel('websocket')
5 | * session.url = 'wss://ws.postman-echo.com/raw'
6 | * def Adapter = Java.type('io.karatelabs.websocket.JsonAdapter')
7 | * session.adapter = new Adapter()
8 | * session.start()
9 |
10 | * session.send({ message: 'hello' })
11 |
12 | * def response = session.collect()
13 | * match response == [{ message: 'hello' }]
14 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/AllRunner.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class AllRunner {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/micronaut/src/main/java/io/karatelabs/examples/HelloController.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples;
2 |
3 | import io.micronaut.http.MediaType;
4 | import io.micronaut.http.annotation.Controller;
5 | import io.micronaut.http.annotation.Get;
6 | import io.micronaut.http.annotation.Produces;
7 |
8 | @Controller("/hello")
9 | public class HelloController {
10 |
11 | @Get
12 | @Produces(MediaType.TEXT_PLAIN)
13 | public String index() {
14 | return "hello world";
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/ssh/src/test/java/karate/SshTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class SshTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/ssh.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/AllRunner.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class AllRunner {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/karate/RmqTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class RmqTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/rabbitmq.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/aws-dynamodb/src/test/java/karate/DynamoDbTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class DynamoDbTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/dynamo-db.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate/GrpcTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class GrpcTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/grpc.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/KafkaTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class KafkaTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/kafka.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/docker/src/test.feature:
--------------------------------------------------------------------------------
1 | Feature: sample karate api test script
2 |
3 | Background:
4 | * url 'https://jsonplaceholder.typicode.com'
5 |
6 | Scenario: get all users and then get the first user by id
7 | * path 'users'
8 | * method get
9 | * status 200
10 | * match response[0] contains { id: 1, name: 'Leanne Graham', website: 'hildegard.org' }
11 |
12 | * def first = response[0]
13 |
14 | * path 'users', first.id
15 | * method get
16 | * status 200
17 | * match response == first
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/karate/KafkaTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class KafkaTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/kafka.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/KafkaJsonTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class KafkaJsonTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/kafka-json.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate/GrpcJavaTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class GrpcJavaTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/grpc-java.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/KafkaJsonTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class KafkaJsonTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/kafka-json.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/KafkaMultiTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class KafkaMultiTest {
9 |
10 | @Test
11 | void testFeature() {
12 | Results results = Runner.path("classpath:karate/kafka-multi.feature").parallel(1);
13 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/EchoTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | class EchoTest {
10 |
11 | @Test
12 | void testFeature() {
13 | Results results = Runner.path("classpath:karate/echo.feature").parallel(1);
14 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/JsonRunner.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | class JsonRunner {
10 |
11 | @Test
12 | void testFeature() {
13 | Results results = Runner.path("classpath:karate/json.feature").parallel(1);
14 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/StompRunner.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | class StompRunner {
10 |
11 | @Test
12 | void testFeature() {
13 | Results results = Runner.path("classpath:karate/stomp.feature").parallel(1);
14 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/KafkaProtoTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | class KafkaProtoTest {
10 |
11 | @Test
12 | void testFeature() {
13 | Results results = Runner.path("classpath:karate/kafka-proto.feature").parallel(1);
14 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/grpc/src/main/proto/hello.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | option java_multiple_files = true;
4 | option java_package = "io.karatelabs.examples.grpc";
5 |
6 | service HelloService {
7 | rpc Hello (HelloRequest) returns (HelloReply) {}
8 | rpc LotsOfReplies (HelloRequest) returns (stream HelloReply) {}
9 | rpc LotsOfGreetings (stream HelloRequest) returns (HelloReply) {}
10 | rpc BidiHello (stream HelloRequest) returns (stream HelloReply) {}
11 | }
12 |
13 | message HelloRequest {
14 | string name = 1;
15 | }
16 |
17 | message HelloReply {
18 | string message = 1;
19 | }
--------------------------------------------------------------------------------
/ssl/src/test/java/ssl/SslTest.java:
--------------------------------------------------------------------------------
1 | package ssl;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.karatelabs.examples.ssl.TestService;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 |
10 | class SslTest {
11 |
12 | @Test
13 | void testAll() {
14 | TestService.main(new String[]{});
15 | Results results = Runner.path("classpath:ssl").parallel(1);
16 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/micronaut/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
7 |
8 | %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/hello.avsc:
--------------------------------------------------------------------------------
1 | {
2 | "type": "record",
3 | "name": "Hello",
4 | "namespace": "io.karatelabs.examples",
5 | "fields": [
6 | {
7 | "name": "message",
8 | "type": "string"
9 | },
10 | {
11 | "name": "info",
12 | "type": {
13 | "name": "Info",
14 | "type": "record",
15 | "fields": [
16 | {
17 | "name": "first",
18 | "type": "long"
19 | },
20 | {
21 | "name": "second",
22 | "type": "boolean"
23 | }
24 | ]
25 | }
26 | }
27 | ]
28 | }
29 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/karate/hello.avsc:
--------------------------------------------------------------------------------
1 | {
2 | "type": "record",
3 | "name": "Hello",
4 | "namespace": "io.karatelabs.examples",
5 | "fields": [
6 | {
7 | "name": "message",
8 | "type": "string"
9 | },
10 | {
11 | "name": "info",
12 | "type": {
13 | "name": "Info",
14 | "type": "record",
15 | "fields": [
16 | {
17 | "name": "first",
18 | "type": "long"
19 | },
20 | {
21 | "name": "second",
22 | "type": "boolean"
23 | }
24 | ]
25 | }
26 | }
27 | ]
28 | }
29 |
--------------------------------------------------------------------------------
/ssl/src/test/java/ssl/ssl-keystore.feature:
--------------------------------------------------------------------------------
1 | Feature: ssl with trust store / cert
2 |
3 | Background:
4 | * configure ssl =
5 | """
6 | {
7 | keyStore: 'classpath:server-keystore.p12',
8 | keyStorePassword: 'karate-mock',
9 | keyStoreType: 'pkcs12',
10 | trustStore: 'classpath:server-keystore.p12',
11 | trustStorePassword: 'karate-mock',
12 | trustStoreType: 'pkcs12'
13 | }
14 | """
15 | * url 'https://localhost:8080'
16 |
17 | Scenario:
18 | * path 'test'
19 | * method get
20 | * status 200
21 | * match response == { success: true }
22 |
--------------------------------------------------------------------------------
/kafka-mtls/conf/ca.cnf:
--------------------------------------------------------------------------------
1 | [ policy_match ]
2 | countryName = match
3 | stateOrProvinceName = match
4 | organizationName = match
5 | organizationalUnitName = optional
6 | commonName = supplied
7 | emailAddress = optional
8 |
9 | [ req ]
10 | prompt = no
11 | distinguished_name = dn
12 | default_md = sha256
13 | default_bits = 4096
14 | x509_extensions = v3_ca
15 |
16 | [ dn ]
17 | countryName = US
18 | organizationName = Karate Labs
19 | commonName = ca
20 |
21 | [ v3_ca ]
22 | subjectKeyIdentifier=hash
23 | basicConstraints = critical,CA:true
24 | authorityKeyIdentifier=keyid:always,issuer:always
25 | keyUsage = critical,keyCertSign,cRLSign
26 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/hello-tls.feature:
--------------------------------------------------------------------------------
1 | Feature: grpc with tls / ssl
2 |
3 | Background:
4 | * def session = karate.channel('grpc')
5 | * session.host = 'localhost'
6 | * session.port = karate.properties['grpc.port']
7 |
8 | # note this short-cut to set multiple session properties on one line
9 | * session.config = { proto: 'classpath:karate/hello.proto', service: 'HelloService', method: 'Hello' }
10 |
11 | * session.trustCert = 'classpath:ca.crt'
12 |
13 | Scenario: unary
14 | * session.send({ name: 'John' })
15 | * match session.pop() == { message: 'hello John' }
16 | * session.send({ name: 'Smith' })
17 | * match session.pop() == { message: 'hello Smith' }
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/io/karatelabs/examples/grpc/HelloTest.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.grpc;
2 |
3 | import io.grpc.Server;
4 | import org.junit.jupiter.api.Test;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 |
9 | class HelloTest {
10 |
11 | static final Logger logger = LoggerFactory.getLogger(HelloTest.class);
12 |
13 | @Test
14 | void testHello() throws Exception {
15 | Server server = HelloServer.start(0);
16 | HelloClient client = new HelloClient("localhost", server.getPort());
17 | String result = client.hello("world");
18 | logger.debug("response is: {}", result);
19 | client.shutdown();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/database/src/main/java/io/karatelabs/examples/database/Dog.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.database;
2 |
3 | public class Dog {
4 |
5 | private int id;
6 | private String name;
7 |
8 | public Dog() {
9 | // zero arg constructor
10 | }
11 |
12 | public Dog(int id, String name) {
13 | this.id = id;
14 | this.name = name;
15 | }
16 |
17 | public int getId() {
18 | return id;
19 | }
20 |
21 | public void setId(int id) {
22 | this.id = id;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/quarkus/src/main/java/io/karatelabs/examples/quarkus/GreetingResource.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.quarkus;
2 |
3 | import jakarta.inject.Inject;
4 | import jakarta.ws.rs.GET;
5 | import jakarta.ws.rs.Path;
6 | import jakarta.ws.rs.Produces;
7 | import jakarta.ws.rs.core.MediaType;
8 |
9 | @Path("/hello")
10 | public class GreetingResource {
11 |
12 | @Inject
13 | GreetingService service;
14 |
15 | @GET
16 | @Produces(MediaType.TEXT_PLAIN)
17 | @Path("/greeting/{name}")
18 | public String greeting(String name) {
19 | return service.greeting(name);
20 | }
21 |
22 | @GET
23 | @Produces(MediaType.TEXT_PLAIN)
24 | public String hello() {
25 | return "hello";
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/axe/README.md:
--------------------------------------------------------------------------------
1 | # Karate and Axe for Accessibility Testing
2 |
3 | It is possible to load any arbitrary JS library and execute it within a Karate UI test. One of the things that this opens up is the possibility to connect [Axe](https://www.deque.com/axe/) and even run a custom report.
4 |
5 | ## Example
6 | Here is a simple example: [axe.feature](https://github.com/karatelabs/karate/blob/master/karate-e2e-tests/src/test/java/axe/axe.feature)
7 |
8 | How it works is very straightforward:
9 | * get the axe library JS / module from a CDN (this can also be from the file-system)
10 | * wait for the page to load and then execute the library
11 | * use a [cusom HTML template](https://github.com/karatelabs/karate#doc) to generate a report
12 |
13 |
14 |
--------------------------------------------------------------------------------
/kafka-mtls/conf/server.cnf:
--------------------------------------------------------------------------------
1 | [req]
2 | prompt = no
3 | distinguished_name = dn
4 | default_md = sha256
5 | default_bits = 4096
6 | req_extensions = v3_req
7 |
8 | [ dn ]
9 | countryName = US
10 | organizationName = Karate Labs
11 | commonName=kafka
12 |
13 | [ v3_ca ]
14 | subjectKeyIdentifier=hash
15 | basicConstraints = critical,CA:true
16 | authorityKeyIdentifier=keyid:always,issuer:always
17 | keyUsage = critical,keyCertSign,cRLSign
18 |
19 | [ v3_req ]
20 | subjectKeyIdentifier = hash
21 | basicConstraints = CA:FALSE
22 | nsComment = "OpenSSL Generated Certificate"
23 | keyUsage = critical, digitalSignature, keyEncipherment
24 | extendedKeyUsage = serverAuth, clientAuth
25 | subjectAltName = @alt_names
26 |
27 | [ alt_names ]
28 | DNS.1=kafka
29 | DNS.2=localhost
30 |
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate/grpc-java.feature:
--------------------------------------------------------------------------------
1 | Feature: example of how to use java interop in a karate test
2 | you can compare this code with HelloTest.java and see how
3 | karate compares one-to-one with the equivalent in java
4 | you can avoid the boilerplate in the background by using a well-designed
5 | utility / helper java class (recommended) refer: grpc.feature
6 |
7 | Background:
8 | * def HelloServer = Java.type('io.karatelabs.examples.grpc.HelloServer')
9 | * def HelloClient = Java.type('io.karatelabs.examples.grpc.HelloClient')
10 | * def server = HelloServer.start(0)
11 | * def client = new HelloClient('localhost', server.getPort())
12 |
13 | Scenario:
14 | * def result = client.hello('world')
15 | * match result == 'hello world'
16 | * client.shutdown()
17 |
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/kafka-json.feature:
--------------------------------------------------------------------------------
1 | Feature: karate-kafka demo
2 |
3 | Background:
4 | * configure kafka =
5 | """
6 | {
7 | 'bootstrap.servers': '127.0.0.1:29092'
8 | }
9 | """
10 |
11 | Scenario:
12 | * def channel = karate.channel('kafka')
13 | * def consumer = channel.consumer()
14 |
15 | * consumer.count = 1
16 | * consumer.topic = 'test-topic'
17 | * consumer.timeout = 5000
18 | * consumer.start()
19 |
20 | * def producer = channel.producer()
21 |
22 | * producer.topic = 'test-topic'
23 | * producer.key = 'first'
24 | * producer.value = { message: 'hello', info: { first: 1, second: true } }
25 | * producer.send()
26 |
27 | * def response = consumer.pop()
28 | * match response.key == 'first'
29 | * match response.value == { message: 'hello', info: { first: 1, second: true } }
--------------------------------------------------------------------------------
/quarkus/src/test/java/karate/GreetingTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.quarkus.test.common.http.TestHTTPResource;
6 | import io.quarkus.test.junit.QuarkusTest;
7 | import java.net.URL;
8 | import static org.junit.jupiter.api.Assertions.*;
9 | import org.junit.jupiter.api.Test;
10 |
11 | @QuarkusTest
12 | class GreetingTest {
13 |
14 | @TestHTTPResource("/")
15 | URL urlBase;
16 |
17 | @Test
18 | void testGreeting() {
19 | Results results = Runner.path("classpath:karate/greeting.feature")
20 | .systemProperty("url.base", urlBase.toString())
21 | .parallel(1);
22 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/cli/README.md:
--------------------------------------------------------------------------------
1 | # Karate and CLI / Bash
2 |
3 | Karate has excellent support for calling external processes via the command-line. You can block and wait for output or you can even fork a process on a separate thread and listen to the output from the test.
4 |
5 | The best documentation is present in [this answer on Stack Overflow](https://stackoverflow.com/a/62911366/143475)
6 |
7 | ## Examples
8 | * [fork.feature](https://github.com/karatelabs/karate/blob/master/karate-core/src/test/java/com/intuit/karate/core/fork.feature)
9 | * [fork-listener.feature](https://github.com/karatelabs/karate/blob/master/karate-core/src/test/java/com/intuit/karate/core/fork-listener.feature)
10 |
11 | ## Further Reading
12 |
13 | [Using cURL to simulate non-standard HTTP request](https://stackoverflow.com/a/64352676/143475)
14 | [Karate and SSH](../ssh/README.md)
--------------------------------------------------------------------------------
/micronaut/src/test/java/karate/HelloTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.micronaut.runtime.server.EmbeddedServer;
6 | import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
7 | import jakarta.inject.Inject;
8 |
9 | import static org.junit.jupiter.api.Assertions.*;
10 | import org.junit.jupiter.api.Test;
11 |
12 | @MicronautTest
13 | class HelloTest {
14 |
15 | @Inject
16 | EmbeddedServer server;
17 |
18 | @Test
19 | void testGreeting() {
20 | Results results = Runner.path("classpath:karate/hello.feature")
21 | .systemProperty("url.base", server.getURL().toString())
22 | .parallel(1);
23 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/aws-dynamodb/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ssl/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/kafka/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/websocket/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/KafkaHybridTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import com.intuit.karate.core.MockServer;
6 | import static org.junit.jupiter.api.Assertions.assertEquals;
7 | import org.junit.jupiter.api.BeforeAll;
8 | import org.junit.jupiter.api.Test;
9 |
10 | class KafkaHybridTest {
11 |
12 | static MockServer server;
13 |
14 | @BeforeAll
15 | static void beforeAll() {
16 | server = MockServer.feature("classpath:karate/mock.feature").build();
17 | }
18 |
19 | @Test
20 | void testHybrid() {
21 | Results results = Runner.path("classpath:karate/kafka-hybrid.feature")
22 | .systemProperty("server.port", server.getPort() + "")
23 | .parallel(1);
24 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/kafka-json.feature:
--------------------------------------------------------------------------------
1 | Feature: karate-kafka demo
2 |
3 | Background:
4 | * configure kafka =
5 | """
6 | {
7 | 'bootstrap.servers': 'localhost:29093',
8 | 'security.protocol': 'SSL',
9 | 'ssl.truststore.location': 'ssl/client.truststore.pkcs12',
10 | 'ssl.truststore.password': 'karate'
11 | }
12 | """
13 |
14 | Scenario:
15 | * def channel = karate.channel('kafka')
16 |
17 | * def consumer = channel.consumer()
18 | * consumer.topic = 'test-topic'
19 | * consumer.count = 1
20 | * consumer.start()
21 |
22 | * def producer = channel.producer()
23 |
24 | * producer.topic = 'test-topic'
25 | * producer.key = 'first'
26 | * producer.value = { message: 'hello', info: { first: 1, second: true } }
27 | * producer.send()
28 |
29 | * def response = consumer.pop()
30 | * match response.key == 'first'
31 | * match response.value == { message: 'hello', info: { first: 1, second: true } }
--------------------------------------------------------------------------------
/grpc/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ssh/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/io/karatelabs/examples/kafka/AvroUtilsRunner.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.kafka;
2 |
3 | import com.intuit.karate.Json;
4 | import org.apache.avro.Schema;
5 | import org.apache.avro.generic.GenericRecord;
6 | import org.junit.jupiter.api.Test;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | class AvroUtilsRunner {
11 |
12 | static final Logger logger = LoggerFactory.getLogger(AvroUtilsRunner.class);
13 |
14 | @Test
15 | void testAvro() {
16 | Schema schema = AvroUtils.toSchema("src/test/java/karate/hello.avsc");
17 | String json = Json.of("{ message: 'hello', info: { first: 5, second: true } }").toString();
18 | GenericRecord record = AvroUtils.fromJson(schema, json);
19 | logger.debug("record: {}", record);
20 | String result = AvroUtils.toJson(record);
21 | logger.debug("result: {}", result);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/KafkaUtils.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Json;
4 | import io.karatelabs.kafka.KarateKafkaProducer;
5 | import java.util.HashMap;
6 | import java.util.Map;
7 | import org.apache.kafka.clients.producer.ProducerRecord;
8 |
9 | public class KafkaUtils {
10 |
11 | public static void send() {
12 | Map map = new HashMap();
13 | map.put("bootstrap.servers", "localhost:29093");
14 | map.put("security.protocol", "SSL");
15 | map.put("ssl.truststore.location", "ssl/client.truststore.pkcs12");
16 | map.put("ssl.truststore.password", "karate");
17 | KarateKafkaProducer producer = new KarateKafkaProducer(map);
18 | String json = Json.of("{ hello: 'world' }").toString();
19 | ProducerRecord pr = new ProducerRecord("test-topic", null, "first", json.getBytes(), null);
20 | producer.send(pr);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/hello-tls-mutual.feature:
--------------------------------------------------------------------------------
1 | Feature: grpc with tls / ssl and using client-side certificate (mutual) auth
2 |
3 | Background:
4 | * def session = karate.channel('grpc')
5 | * session.host = 'localhost'
6 | * session.port = karate.properties['grpc.port']
7 |
8 | * session.config = { trustCert: 'classpath:ca.crt', clientCert: 'classpath:client.crt', clientKey: 'classpath:client.pem' }
9 |
10 | # note that session.config can be updated multiple times
11 | * def method = 'Hello'
12 | # and that everything is pure-JS which means Karate variable references work directly
13 | * session.config = { proto: 'classpath:karate/hello.proto', service: 'HelloService', method: method }
14 |
15 | Scenario: unary
16 | * session.send({ name: 'John' })
17 | * match session.pop() == { message: 'hello John' }
18 | * session.send({ name: 'Smith' })
19 | * match session.pop() == { message: 'hello Smith' }
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/grpc-custom/src/main/java/io/karatelabs/examples/grpc/HelloServer.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.grpc;
2 |
3 | import io.grpc.Server;
4 | import io.grpc.ServerBuilder;
5 | import io.grpc.stub.StreamObserver;
6 |
7 | public class HelloServer extends HelloServiceGrpc.HelloServiceImplBase {
8 |
9 | @Override
10 | public void hello(HelloRequest request, StreamObserver response) {
11 | HelloReply reply = HelloReply.newBuilder().setMessage("hello " + request.getName()).build();
12 | response.onNext(reply);
13 | response.onCompleted();
14 | }
15 |
16 | public static Server start(int port) throws Exception {
17 | Server server = ServerBuilder.forPort(port)
18 | .addService(new HelloServer())
19 | .build()
20 | .start();
21 | System.out.println("grpc server started on port: " + server.getPort());
22 | return server;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/grpc/README.md:
--------------------------------------------------------------------------------
1 | # Karate and gRPC
2 |
3 | Karate has native support for gRPC as an optional dependency (non-open source and commercial). Enterprise users can find more information here: [Karate-gRPC](https://github.com/karatelabs/karate-addons/tree/main/karate-grpc).
4 |
5 | A license is required for running (for e.g. in CI/CD) and a Karate Labs IDE subscription is required per developer seat. Make sure you have a `.karate/karate.lic` file in place before running the example.
6 |
7 | ## Running
8 | This is a normal Java / Maven project so running `mvn clean compile test` will be sufficient to run all the tests.
9 |
10 | Take a look at [`hello.feature`](src/test/java/karate/hello.feature) to see how simple yet expressive gRPC tests can be.
11 |
12 | ## Further Reading
13 | * [grpc-custom](../grpc-custom/README.md) - it is possible to test gRPC by writing the Java integration code yourself and generating Java code, but the approach above is recommended
14 |
15 |
--------------------------------------------------------------------------------
/browserstack/browserstack.feature:
--------------------------------------------------------------------------------
1 | Feature: browserstack automation demo
2 |
3 | Background:
4 | # enter the value for the next line from your browserstack account
5 | * def browserStackUrl = ''
6 | * def browserStackOptions = { projectName: 'Karate and Browser Stack', buildName: 'myBuild', sessionName: '#(karate.feature.prefixedPath)' }
7 | * def session = { capabilities: { alwaysMatch: { browserName: 'chrome', browserVersion: 'latest', platformName: 'Windows 11', 'bstack:options': '#(browserStackOptions)' } } }
8 | * configure driver = { type: 'chromedriver', start: false, webDriverSession: '#(session)', webDriverUrl: '#(browserStackUrl)' }
9 |
10 | Scenario: try to login to github and check for expected error message
11 | * driver 'https://github.com/login'
12 | * input('#login_field', 'XXXX')
13 | * input('#password', 'world')
14 | * submit().click("input[name=commit]")
15 | * match html('.flash-error') contains 'Incorrect username or password.'
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/kafka-proto.feature:
--------------------------------------------------------------------------------
1 | Feature: karate-kafka demo
2 |
3 | Background:
4 | * configure kafka =
5 | """
6 | {
7 | 'bootstrap.servers': '127.0.0.1:29092'
8 | }
9 | """
10 | * def channel = karate.channel('kafka')
11 | * channel.register({ name: 'hello-proto', path: 'classpath:karate/hello.proto', message: 'Hello', roots: ['classpath:karate'] })
12 |
13 | Scenario:
14 | * def consumer = channel.consumer()
15 | * consumer.count = 1
16 | * consumer.topic = 'test-topic'
17 | * consumer.schema = 'hello-proto'
18 | * consumer.start()
19 |
20 | * def producer = channel.producer()
21 |
22 | * producer.topic = 'test-topic'
23 | * producer.schema = 'hello-proto'
24 | * producer.key = 'first'
25 | * producer.value = { message: 'hello', sender: { name: 'John Smith' } }
26 | * producer.send()
27 |
28 | * def response = consumer.collect()
29 | * match response[0].key == 'first'
30 | * match response[0].value == { message: 'hello', sender: { name: 'John Smith' } }
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/io/karatelabs/examples/kafka/KarateKafkaRunner.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.kafka;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | public class KarateKafkaRunner {
11 |
12 | static final Logger logger = LoggerFactory.getLogger(KarateKafkaRunner.class);
13 |
14 | @Test
15 | void testKafka() throws Exception {
16 | String topic = "test-topic";
17 | KarateKafkaConsumer consumer = new KarateKafkaConsumer(topic);
18 | KarateKafkaProducer producer = new KarateKafkaProducer(topic);
19 | producer.send("hello world");
20 | List messages = consumer.getMessages();
21 | logger.debug("got messages: {}", messages);
22 | assertEquals(Arrays.asList("hello world"), messages);
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/kafka-mtls/src/test/java/karate/kafka-hybrid.feature:
--------------------------------------------------------------------------------
1 | Feature:
2 |
3 | Background:
4 | * configure kafka =
5 | """
6 | {
7 | 'bootstrap.servers': 'localhost:29093',
8 | 'security.protocol': 'SSL',
9 | 'ssl.truststore.location': 'ssl/client.truststore.pkcs12',
10 | 'ssl.truststore.password': 'karate'
11 | }
12 | """
13 |
14 | Scenario:
15 | # set up the listener before triggering any kafka events
16 | * def channel = karate.channel('kafka')
17 |
18 | * def consumer = channel.consumer()
19 |
20 | * consumer.topic = 'test-topic'
21 | * consumer.count = 1
22 | * consumer.start()
23 |
24 | # this api call will trigger a kafka message (from mock.feature)
25 | * url 'http://localhost:' + karate.properties['server.port']
26 | * method get
27 | * match response == { success: true }
28 |
29 | # here we wait until the session gets the expected message
30 | * def response = consumer.pop()
31 | * match response.key == 'first'
32 | * match response.value == { hello: 'world' }
33 |
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/io/karatelabs/examples/rabbitMQ/KarateRMQRunner.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.rabbitMQ;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import static org.junit.jupiter.api.Assertions.*;
6 | import org.junit.jupiter.api.Test;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | public class KarateRmqRunner {
11 |
12 | static final Logger logger = LoggerFactory.getLogger(KarateRmqRunner.class);
13 |
14 | @Test
15 | void testRMQ() throws Exception {
16 | String queueName = "my-queue";
17 | KarateRmqConsumer consumer = new KarateRmqConsumer(queueName);
18 | KarateRmqProducer producer = new KarateRmqProducer(queueName);
19 | producer.putMessage("hello world");
20 | List messages = consumer.getMessageList();
21 | logger.debug("messages: {}", messages);
22 | assertEquals(Arrays.asList("hello world"), messages);
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/micronaut/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/quarkus/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/database/src/test/java/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
7 |
8 |
9 |
10 |
11 | target/karate.log
12 |
13 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/lambdatest/lambdatest.feature:
--------------------------------------------------------------------------------
1 | Feature: lambdatest automation demo
2 |
3 | Background:
4 | # enter the values for the next few lines from your lambatest account
5 | * def lambdaTestUser = ''
6 | * def lambdaTestKey = ''
7 | * def lambdaTestUrl = 'https://hub.lambdatest.com/wd/hub'
8 | * def lambdaTestOptions = { project: '#(karate.feature.prefixedPath)', username: '#(lambdaTestUser)', accessKey: '#(lambdaTestKey)' }
9 | * def session = { capabilities: { alwaysMatch: { browserName: 'chrome', browserVersion: 'latest', platformName: 'Windows 11', 'LT:Options': '#(lambdaTestOptions)' } } }
10 | * configure driver = { type: 'chromedriver', start: false, webDriverSession: '#(session)', webDriverUrl: '#(lambdaTestUrl)' }
11 |
12 | Scenario: try to login to github and check for expected error message
13 | * driver 'https://github.com/login'
14 | * input('#login_field', 'XXXX')
15 | * input('#password', 'world')
16 | * submit().click("input[name=commit]")
17 | * match html('.flash-error') contains 'Incorrect username or password.'
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/HelloTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.grpc.Server;
6 | import io.karatelabs.examples.grpc.HelloServer;
7 | import org.junit.jupiter.api.AfterAll;
8 | import org.junit.jupiter.api.BeforeAll;
9 | import org.junit.jupiter.api.Test;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | class HelloTest {
14 |
15 | static Server server;
16 |
17 | @BeforeAll
18 | static void beforeAll() throws Exception {
19 | server = HelloServer.start(0, false);
20 | }
21 |
22 | @Test
23 | void testFeature() {
24 | Results results = Runner.path("classpath:karate/hello.feature")
25 | .systemProperty("grpc.port", server.getPort() + "")
26 | .parallel(1);
27 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
28 | }
29 |
30 | @AfterAll
31 | static void afterAll() {
32 | server.shutdownNow();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/jbang/README.md:
--------------------------------------------------------------------------------
1 | # Karate and JBang
2 |
3 | [JBang](https://www.jbang.dev) is a good option for teams that don't want to install Java or an IDE or worry about compiling code. This simple example uses the [Java Faker](https://github.com/DiUS/java-faker) library to generate a user name and then make an API call.
4 |
5 | * [karate.java](karate.java) - this sets up Karate and adds the Java Faker dependency to the classpath
6 | * [test.feature](test.feature) - a simple test that uses the Java Faker Java API to generate a person name
7 |
8 | ## Running
9 | With JBang installed, this command will run the tests. You can replace `.` with any valid path that contains `*.feature` files.
10 |
11 | ```
12 | jbang karate.java .
13 | ```
14 |
15 | ## Further Reading
16 |
17 | * [Other Runtime Options](https://github.com/karatelabs/karate/wiki/Get-Started:-Other-Runtime-Options)
18 | * [Karate, JBang and NPM](../jbang-npm/README.md) - for those who want to use 3rd party Java libraries or custom code and avoid Java compilation and Maven
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/HelloTlsTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.grpc.Server;
6 | import io.karatelabs.examples.grpc.HelloServer;
7 | import org.junit.jupiter.api.AfterAll;
8 | import org.junit.jupiter.api.BeforeAll;
9 | import org.junit.jupiter.api.Test;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | class HelloTlsTest {
14 |
15 | static Server server;
16 |
17 | @BeforeAll
18 | static void beforeAll() throws Exception {
19 | server = HelloServer.start(0, true);
20 | }
21 |
22 | // @Test
23 | void testFeature() {
24 | Results results = Runner.path("classpath:karate/hello-tls.feature")
25 | .systemProperty("grpc.port", server.getPort() + "")
26 | .parallel(1);
27 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
28 | }
29 |
30 | @AfterAll
31 | static void afterAll() {
32 | server.shutdownNow();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/grpc/src/test/java/karate/HelloTlsMutualTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.grpc.Server;
6 | import io.karatelabs.examples.grpc.HelloServer;
7 | import org.junit.jupiter.api.AfterAll;
8 | import org.junit.jupiter.api.BeforeAll;
9 | import org.junit.jupiter.api.Test;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | class HelloTlsMutualTest {
14 |
15 | static Server server;
16 |
17 | @BeforeAll
18 | static void beforeAll() throws Exception {
19 | server = HelloServer.start(0, true);
20 | }
21 |
22 | // @Test
23 | void testFeature() {
24 | Results results = Runner.path("classpath:karate/hello-tls-mutual.feature")
25 | .systemProperty("grpc.port", server.getPort() + "")
26 | .parallel(1);
27 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
28 | }
29 |
30 | @AfterAll
31 | static void afterAll() {
32 | server.shutdownNow();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/kafka-custom/src/test/java/karate/KafkaUtils.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Logger;
4 | import com.intuit.karate.core.ScenarioEngine;
5 | import io.karatelabs.examples.kafka.KarateKafkaConsumer;
6 | import io.karatelabs.examples.kafka.KarateKafkaProducer;
7 | import java.util.List;
8 |
9 | public class KafkaUtils {
10 |
11 | private final String topic;
12 | private final KarateKafkaConsumer consumer;
13 | private final KarateKafkaProducer producer;
14 |
15 | public KafkaUtils(String topic) {
16 | this.topic = topic;
17 | consumer = new KarateKafkaConsumer(topic);
18 | producer = new KarateKafkaProducer(topic);
19 | }
20 |
21 | private static Logger logger() {
22 | ScenarioEngine engine = ScenarioEngine.get();
23 | return engine.logger;
24 | }
25 |
26 | public void send(Object data) {
27 | logger().debug(">> kafka send [{}]", topic);
28 | producer.send(data);
29 | }
30 |
31 | public List listen() {
32 | return consumer.getMessages();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/ssl/README.md:
--------------------------------------------------------------------------------
1 | # Karate and SSL
2 |
3 | This is a "standard" [Spring Boot](https://spring.io/projects/spring-boot) project.
4 |
5 | It shows how to test a server that uses a trust-store and / or keystore for security.
6 |
7 | The relevant Karate documentation can be found here: [X509 Certificate Authentication](https://github.com/karatelabs/karate#x509-certificate-authentication).
8 |
9 | Run the server from the IDE or via Maven using this command:
10 |
11 | ```
12 | mvn -Dexec.mainClass=io.karatelabs.examples.ssl.TestService compile exec:java
13 | ```
14 |
15 | This will start an HTTPS server on port 8080.
16 |
17 | Now you can run the two Karate tests individually from the IDE.
18 |
19 | Or by using the [SslRunner](src/test/java/ssl/SslRunner.java) JUnit helper.
20 |
21 | ```
22 | mvn test -Dtest=SslRunner
23 | ```
24 |
25 | You can also run the test suite that will start the server automatically.
26 |
27 | ```
28 | mvn test
29 | ```
30 |
31 | ## Further Reading
32 | * [Karate and Spring Boot](../spring-boot/README.md)
33 | * [Karate and Databases](../database/README.md)
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/saucelabs/saucelabs.feature:
--------------------------------------------------------------------------------
1 | Feature: sauce labs automation demo
2 |
3 | Background:
4 | # enter the values for the next few lines from your sauce labs account
5 | * def sauceLabsBuild = ''
6 | * def sauceLabsUser = ''
7 | * def sauceLabsKey = ''
8 | * def sauceLabsUrl = 'https://ondemand.eu-central-1.saucelabs.com:443/wd/hub'
9 | * def sauceOptions = { build: '#(sauceLabsBuild)', name: '#(karate.feature.prefixedPath)', username: '#(sauceLabsUser)', accessKey: '#(sauceLabsKey)' }
10 | * def session = { capabilities: { alwaysMatch: { browserName: 'chrome', browserVersion: 'latest', platformName: 'Windows 11', 'sauce:options': '#(sauceOptions)' } } }
11 | * configure driver = { type: 'chromedriver', start: false, webDriverSession: '#(session)', webDriverUrl: '#(sauceLabsUrl)' }
12 |
13 | Scenario: try to login to github and check for expected error message
14 | * driver 'https://github.com/login'
15 | * input('#login_field', 'XXXX')
16 | * input('#password', 'world')
17 | * submit().click("input[name=commit]")
18 | * match html('.flash-error') contains 'Incorrect username or password.'
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Karate Labs
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/rabbitmq/src/test/java/karate/RMQUtils.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Logger;
4 | import com.intuit.karate.core.ScenarioEngine;
5 | import io.karatelabs.examples.rabbitMQ.KarateRmqConsumer;
6 | import io.karatelabs.examples.rabbitMQ.KarateRmqProducer;
7 |
8 | import java.io.IOException;
9 | import java.util.List;
10 | import java.util.concurrent.TimeoutException;
11 |
12 | public class RmqUtils {
13 |
14 | private final KarateRmqConsumer consumer;
15 | private final KarateRmqProducer producer;
16 |
17 | public RmqUtils(String queueName) throws IOException, TimeoutException {
18 | consumer = new KarateRmqConsumer(queueName);
19 | producer = new KarateRmqProducer(queueName);
20 | }
21 |
22 | private static Logger logger() {
23 | ScenarioEngine engine = ScenarioEngine.get();
24 | return engine.logger;
25 | }
26 |
27 | public void send(String message) throws IOException {
28 | logger().debug(">> RMQ send - {}", message);
29 | producer.putMessage(message);
30 | }
31 |
32 | public List listen() throws IOException {
33 | return consumer.getMessageList();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/grpc-custom/src/main/java/io/karatelabs/examples/grpc/HelloClient.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.grpc;
2 |
3 | import io.grpc.ManagedChannel;
4 | import io.grpc.ManagedChannelBuilder;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | public class HelloClient {
8 |
9 | private final ManagedChannel channel;
10 | private final HelloServiceGrpc.HelloServiceBlockingStub stub;
11 |
12 | HelloClient(ManagedChannel channel) {
13 | this.channel = channel;
14 | stub = HelloServiceGrpc.newBlockingStub(channel);
15 | }
16 |
17 | public HelloClient(String host, int port) {
18 | this(ManagedChannelBuilder.forAddress(host, port)
19 | // channels are secure by default (SSL / TLS)
20 | // we use plaintext to avoid needing certificates
21 | .usePlaintext()
22 | .build());
23 | }
24 |
25 | public String hello(String message) {
26 | HelloReply resp = stub.hello(HelloRequest.newBuilder().setName(message).build());
27 | return resp.getMessage();
28 | }
29 |
30 | public void shutdown() throws InterruptedException {
31 | channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/database/src/test/java/karate/dogs.feature:
--------------------------------------------------------------------------------
1 | Feature: dogs end-point that uses jdbc as part of the test
2 |
3 | Background:
4 | * url urlBase
5 |
6 | Scenario: create and retrieve a dog
7 |
8 | # create a dog
9 | * path 'dogs'
10 | * request { name: 'Scooby' }
11 | * method post
12 | * status 200
13 | * match response == { id: '#number', name: 'Scooby' }
14 |
15 | * def id = response.id
16 |
17 | # get by id
18 | * path 'dogs', id
19 | * method get
20 | * status 200
21 | * match response == { id: '#(id)', name: 'Scooby' }
22 |
23 | # get all dogs
24 | * path 'dogs'
25 | * method get
26 | * status 200
27 | * match response contains { id: '#(id)', name: 'Scooby' }
28 |
29 | # use jdbc to validate
30 | # look at karate-config.js to see how "db" was initialized
31 |
32 | # since the DbUtils returns a Java List (of Map-s), it becomes normal JSON here !
33 | # which means that you can use the full power of Karate's 'match' syntax
34 | * def dogs = db.readRows('SELECT * FROM DOGS')
35 | * match dogs contains { ID: '#(id)', NAME: 'Scooby' }
36 |
37 | * def dog = db.readRow('SELECT * FROM DOGS D WHERE D.ID = ' + id)
38 | * match dog.NAME == 'Scooby'
39 |
40 | * def test = db.readValue('SELECT ID FROM DOGS D WHERE D.ID = ' + id)
41 | * match test == id
42 |
--------------------------------------------------------------------------------
/kafka/docker-compose.yml:
--------------------------------------------------------------------------------
1 | services:
2 |
3 | zookeeper:
4 | image: confluentinc/cp-zookeeper:latest
5 | ports:
6 | - 22181:2181
7 | environment:
8 | ZOOKEEPER_CLIENT_PORT: 2181
9 | ZOOKEEPER_TICK_TIME: 2000
10 |
11 | kafka:
12 | image: confluentinc/cp-kafka:latest
13 | depends_on:
14 | - zookeeper
15 | ports:
16 | - 29092:29092
17 | environment:
18 | KAFKA_BROKER_ID: 1
19 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
20 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
21 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
22 | KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
23 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
24 | KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: 1
25 | KAFKA_MIN_INSYNC_REPLICAS: 1
26 | KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
27 |
28 | schema-registry:
29 | image: confluentinc/cp-schema-registry:latest
30 | depends_on:
31 | - zookeeper
32 | - kafka
33 | ports:
34 | - 8081:8081
35 | environment:
36 | SCHEMA_REGISTRY_HOST_NAME: localhost
37 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka:9092
38 |
--------------------------------------------------------------------------------
/rabbitmq/README.md:
--------------------------------------------------------------------------------
1 | # Karate and RabbitMQ
2 |
3 | This sample project demonstrates how you can test RabbitMQ messaging with a Java client.
4 |
5 | When you use well designed utility classes, your Karate tests will be clean and only focus on making a call and what data is sent and received.
6 |
7 | For example if you look at [`rabbitmq.feature`](src/test/java/karate/rabbitmq.feature) the test is just a few lines. Behind the scenes a Rabbit consumer and producer is initialized and a message is passed. The HTML report even includes details of the "put" operation, which you can easily customize, or extend to other operations.
8 |
9 | ## Running
10 |
11 | * Docker is required to start the RabbitMQ server. There is a `docker-compose.yml` file in this project.
12 | * `docker-compose up -d`
13 | * `mvn test`
14 | * To stop the Docker container run `docker-compose down`
15 |
16 | ### References
17 | * https://x-team.com/blog/set-up-rabbitmq-with-docker-compose/
18 | * https://www.rabbitmq.com/download.html
19 | * [Kafka example](../kafka/README.md)
20 | * [ActiveMQ example](https://github.com/karatelabs/karate/tree/master/karate-netty#consumer-provider-example)
21 | * [Async and Mocks example](https://twitter.com/getkarate/status/1417023536082812935)
22 |
23 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/server.csr:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE REQUEST-----
2 | MIIDMTCCAhkCAQAwMzELMAkGA1UEBhMCVVMxFDASBgNVBAoMC0thcmF0ZSBMYWJz
3 | MQ4wDAYDVQQDDAVrYWZrYTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
4 | AMP+MMq9DZO2Ynenhf2BLi1eaMNi4jrWgW9Mq4EU6IjrjG4YiJnPIy8d5QUANcub
5 | Y5YpZ2lUtbVjN6eIRBf2g6r/73u5sXbJx1A/SRZMEEhojDC+SmL1Bg4AAuvI+vaN
6 | NW0Gar9gWRWRGuk3qQ4+X8M/qfRRg9TdheIyDiSNaf6S/OakpR32bqfamxNNk568
7 | EDDio+TSM7t3MP61JaPMZ+Pk7dKI3KoUz/h2kBLtsWmZYxTG8fOxghnk6Ql15yMh
8 | eFRa8f2ZDoGgLKZuZ1yyrzQsU8cCRwSsTQlZuWh4GmHdDuYOqWUQ5GlyfHjyrtnf
9 | aUCFVLz9wuCnUVBL6QLuAKsCAwEAAaCBuDCBtQYJKoZIhvcNAQkOMYGnMIGkMB0G
10 | A1UdDgQWBBTuUuupXC/x8W0D/TB9Nx4BTvN42zAJBgNVHRMEAjAAMCwGCWCGSAGG
11 | +EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAOBgNVHQ8BAf8E
12 | BAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBsGA1UdEQQUMBKC
13 | BWthZmthgglsb2NhbGhvc3QwDQYJKoZIhvcNAQELBQADggEBAGOldAq/pzegqHXr
14 | AZPvwGI18fkl49vqL5FaRr/DR919FYEcHoHztRH/Ce7xT8bOy12X+lJARSL4gn+x
15 | KtC/TBGVen9AQhvnoNwFqOiLtb2tBNPCdmOS8mvHJtuYZjcDzlCvyFQzUib4T7Qo
16 | 46opuS81kFwANh17760orbj2FMDOu/FU0XVMzP3ayFgyth3bFX68U4Ml7F+Xb3LH
17 | t+qY/CtMqavJj6+g8LwwX5qIeDmAE+dxtouRcsd2bWIx0A6Qe4NG1MF4cynKoVpf
18 | DPeQa4jT5xI68l1auZppMzdT4iCECv5Uh39QIFutog0aTIR42XTokv7Hs+en1lwI
19 | cXWFees=
20 | -----END CERTIFICATE REQUEST-----
21 |
--------------------------------------------------------------------------------
/kafka-custom/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 |
4 | zookeeper:
5 | image: confluentinc/cp-zookeeper:latest
6 | ports:
7 | - 22181:2181
8 | environment:
9 | ZOOKEEPER_CLIENT_PORT: 2181
10 | ZOOKEEPER_TICK_TIME: 2000
11 |
12 | kafka:
13 | image: confluentinc/cp-kafka:latest
14 | depends_on:
15 | - zookeeper
16 | ports:
17 | - 29092:29092
18 | environment:
19 | KAFKA_BROKER_ID: 1
20 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
21 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
22 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
23 | KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
24 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
25 | KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: 1
26 | KAFKA_MIN_INSYNC_REPLICAS: 1
27 | KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
28 |
29 | schema-registry:
30 | image: confluentinc/cp-schema-registry:latest
31 | depends_on:
32 | - zookeeper
33 | - kafka
34 | ports:
35 | - 8081:8081
36 | environment:
37 | SCHEMA_REGISTRY_HOST_NAME: localhost
38 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka:9092
39 |
--------------------------------------------------------------------------------
/kafka-mtls/docker-compose.yml:
--------------------------------------------------------------------------------
1 | services:
2 |
3 | zookeeper:
4 | image: confluentinc/cp-zookeeper:latest
5 | ports:
6 | - 22181:2181
7 | environment:
8 | ZOOKEEPER_CLIENT_PORT: 2181
9 | ZOOKEEPER_TICK_TIME: 2000
10 |
11 | kafka:
12 | image: confluentinc/cp-kafka:latest
13 | hostname: kafka
14 | depends_on:
15 | - zookeeper
16 | ports:
17 | - 29092:29092
18 | - 29093:29093
19 | environment:
20 | KAFKA_BROKER_ID: 1
21 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
22 | KAFKA_LISTENERS: PLAINTEXT://kafka:29092,SSL://kafka:29093,BROKER://kafka:9092
23 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092,SSL://localhost:29093,BROKER://kafka:9092
24 | KAFKA_INTER_BROKER_LISTENER_NAME: BROKER
25 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,SSL:SSL,BROKER:PLAINTEXT
26 | KAFKA_SSL_KEYSTORE_FILENAME: server.keystore.pkcs12
27 | KAFKA_SSL_KEYSTORE_CREDENTIALS: creds_keystore
28 | KAFKA_SSL_KEY_CREDENTIALS: creds_sslkey
29 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
30 | KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: 1
31 | KAFKA_MIN_INSYNC_REPLICAS: 1
32 | KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
33 | volumes:
34 | - ./ssl:/etc/kafka/secrets
35 |
--------------------------------------------------------------------------------
/database/src/test/java/karate/DogsTest.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Results;
4 | import com.intuit.karate.Runner;
5 | import io.karatelabs.examples.database.Application;
6 | import static org.junit.jupiter.api.Assertions.*;
7 | import org.junit.jupiter.api.Test;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
13 |
14 | @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
15 | class DogsTest {
16 |
17 | static final Logger logger = LoggerFactory.getLogger(DogsTest.class);
18 |
19 | @Autowired
20 | private ServletWebServerApplicationContext webContext;
21 |
22 | @Test
23 | void testFeature() {
24 | int port = webContext.getWebServer().getPort();
25 | logger.debug("server port detected as: {}", port);
26 | Results results = Runner.path("classpath:karate/dogs.feature")
27 | .systemProperty("server.port", port + "")
28 | .parallel(1);
29 | assertEquals(0, results.getFailCount(), results.getErrorMessages());
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/ca.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDiTCCAnGgAwIBAgIJAN7uVLWpEtQTMA0GCSqGSIb3DQEBCwUAMDAxCzAJBgNV
3 | BAYTAlVTMRQwEgYDVQQKDAtLYXJhdGUgTGFiczELMAkGA1UEAwwCY2EwHhcNMjMx
4 | MjA2MDgyNTI4WhcNMjQxMjA1MDgyNTI4WjAwMQswCQYDVQQGEwJVUzEUMBIGA1UE
5 | CgwLS2FyYXRlIExhYnMxCzAJBgNVBAMMAmNhMIIBIjANBgkqhkiG9w0BAQEFAAOC
6 | AQ8AMIIBCgKCAQEAviBwCANI/NLnUtkTbmerkO+8ySMNciLO+eNe+E5thH3Vg1GQ
7 | Yyj5vFL3tOCw6l4UTRAV4rXLSnMMEA2R1kAmKwlk+w45yg3b2kNdTq8mtgrqOv6/
8 | NtkKjqLl3QKl8JfeIcmB9Rh8VstYZXdkQ48XKLd0gAaGDfh2pWzjiGGDP8tdEVYa
9 | n5a18rlZ8UFaWNtTbFm4mya4EQQEeSspYn00wcdqmklQUQ7OrBBFpHjlbUDurj4Q
10 | Ci9MZvC5WFwh8VFDCD/zaTlQ8quuw/peITlkJT2cUW6Gd9pBIjxCmuNx1THsns2Y
11 | nLjrBUQ8rvc0Kz4fV93DZsjmRdzE0MtSRQ/fPwIDAQABo4GlMIGiMB0GA1UdDgQW
12 | BBR2IEmMF5SOg5uCMaJ41aPfb3OcsDAPBgNVHRMBAf8EBTADAQH/MGAGA1UdIwRZ
13 | MFeAFHYgSYwXlI6Dm4IxonjVo99vc5ywoTSkMjAwMQswCQYDVQQGEwJVUzEUMBIG
14 | A1UECgwLS2FyYXRlIExhYnMxCzAJBgNVBAMMAmNhggkA3u5UtakS1BMwDgYDVR0P
15 | AQH/BAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQBercJWzrHx05fjj8+r8q3vUWuz
16 | iqhCBs3H8k+48PcHjEqAKKdIttdysJE1g95LNEeQD23NSM1d5mJU9fmQcN2UUv7D
17 | 2dbMB3/nV27YoS93srOPyGPpf2qmE0LQtDTt1M+H+hhWJIlFvMkdvxS86XK9tpiz
18 | c1ZkgHgP9PgITYKaCUl7B30lFXWk3QJQ4ns8TZDIoaPAv52/UrDvWz1drk9rQneN
19 | u7yX3WpqdCJq1SxBq9TarPZZvAgnUkMS3i143F4Zt51pFnzr3S3PEfb71AloAOpw
20 | AoMrapFGkTrURJL+kcgDeQMY72vsy6cdGRQ/NJxMzaSFRqQlsqEoWvzhjg5W
21 | -----END CERTIFICATE-----
22 |
--------------------------------------------------------------------------------
/spring-boot/README.md:
--------------------------------------------------------------------------------
1 | # Karate and Spring Boot
2 |
3 | Since Karate fits well into Maven and Gradle projects, it is easy to run Karate tests as part of a Spring Boot project. You can start and stop the main application from a JUnit class and then run your Karate test-suite.
4 |
5 | * [examples/database](../database/README.md) - this is a "standard" Spring Boot project that shows how to combine Karate with the `@SpringBootTest` annotation to test a REST service as well as a database via JDBC
6 | * [examples/ssl](../ssl/README.md) - another minimal Spring Boot project that shows how to test SSL / MTLS using client-side certificates configured.
7 | * [karate-demo](https://github.com/karatelabs/karate/tree/master/karate-demo) - this is part of the main Karate open-source project, and has examples of how to use Karate to test a Spring Boot application
8 | * [consumer-driven-contracts](https://github.com/karatelabs/karate/tree/master/examples/consumer-driven-contracts) - this is a multi-module Maven project that is focused on testing a Spring Boot application
9 | * [hello-karate](https://github.com/Sdaas/hello-karate) - an example created by the community, which tests a Spring Boot REST service using Karate from within IntelliJ, Maven, and Gradle.
10 |
11 | ## Further Reading
12 |
13 | [Karate and Spring Boot on Stack Overflow](https://stackoverflow.com/search?q=%5Bkarate%5D+spring+boot)
14 |
15 |
--------------------------------------------------------------------------------
/grpc-custom/src/test/java/karate/GrpcUtils.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import com.intuit.karate.Logger;
4 | import com.intuit.karate.core.ScenarioEngine;
5 | import io.grpc.Server;
6 | import io.karatelabs.examples.grpc.HelloClient;
7 | import io.karatelabs.examples.grpc.HelloServer;
8 |
9 | public class GrpcUtils {
10 |
11 | private static final GrpcUtils INSTANCE = new GrpcUtils();
12 |
13 | private final HelloClient client;
14 |
15 | private GrpcUtils() {
16 | try {
17 | Server server = HelloServer.start(0);
18 | client = new HelloClient("localhost", server.getPort());
19 | } catch (Exception e) {
20 | throw new RuntimeException(e);
21 | }
22 | }
23 |
24 | private static Logger logger() {
25 | ScenarioEngine engine = ScenarioEngine.get();
26 | return engine.logger;
27 | }
28 |
29 | // the logging will appear in the html report for grpc.feature
30 | public static String hello(String message) {
31 | Logger logger = logger();
32 | logger.debug("grpc call to hello()");
33 | logger.debug("====================");
34 | logger.debug(">> hello: {}", message);
35 | String result = INSTANCE.client.hello(message);
36 | logger.debug("<< hello: {}", result);
37 | return result;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/kafka-mtls/ssl/server.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDjjCCAnagAwIBAgIJAMcRVm7v9DVlMA0GCSqGSIb3DQEBCwUAMDAxCzAJBgNV
3 | BAYTAlVTMRQwEgYDVQQKDAtLYXJhdGUgTGFiczELMAkGA1UEAwwCY2EwHhcNMjMx
4 | MjA2MDgyNTU5WhcNMzMxMjAzMDgyNTU5WjAzMQswCQYDVQQGEwJVUzEUMBIGA1UE
5 | CgwLS2FyYXRlIExhYnMxDjAMBgNVBAMMBWthZmthMIIBIjANBgkqhkiG9w0BAQEF
6 | AAOCAQ8AMIIBCgKCAQEAw/4wyr0Nk7Zid6eF/YEuLV5ow2LiOtaBb0yrgRToiOuM
7 | bhiImc8jLx3lBQA1y5tjlilnaVS1tWM3p4hEF/aDqv/ve7mxdsnHUD9JFkwQSGiM
8 | ML5KYvUGDgAC68j69o01bQZqv2BZFZEa6TepDj5fwz+p9FGD1N2F4jIOJI1p/pL8
9 | 5qSlHfZup9qbE02TnrwQMOKj5NIzu3cw/rUlo8xn4+Tt0ojcqhTP+HaQEu2xaZlj
10 | FMbx87GCGeTpCXXnIyF4VFrx/ZkOgaAspm5nXLKvNCxTxwJHBKxNCVm5aHgaYd0O
11 | 5g6pZRDkaXJ8ePKu2d9pQIVUvP3C4KdRUEvpAu4AqwIDAQABo4GnMIGkMB0GA1Ud
12 | DgQWBBTuUuupXC/x8W0D/TB9Nx4BTvN42zAJBgNVHRMEAjAAMCwGCWCGSAGG+EIB
13 | DQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAOBgNVHQ8BAf8EBAMC
14 | BaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBsGA1UdEQQUMBKCBWth
15 | Zmthgglsb2NhbGhvc3QwDQYJKoZIhvcNAQELBQADggEBAL2WHxZQQdMwlWp2fs9f
16 | D5WShSG8dvELB7foC2vKn57/DmLWsnaiLZs8PH6MMXC8FyLHlS/qlgp2CWHG/P7d
17 | nBuElGn8o4pL2znA4+xBG7f1sCuNT+PG/zG5x+sxqCor8iObw2IWVUTbKt6oQNsg
18 | 8J/fVb11TUt0AvPwk/HqRlQyJFPv1GprOsaK4JE1BlLewbkDVG9Bx+0UAYBqcdnB
19 | wP8bv3h51CogesYgULZeq49SHVQ+uxc5rxysSenz2TmJUUnRuXCeczPB93jJrU/4
20 | 5yExhJsS6v6Zr3uHTW59oxQz+QVk8v6ax+liZsu6omk7Krcz9eD7PqkoGH1UOJYn
21 | uXU=
22 | -----END CERTIFICATE-----
23 |
--------------------------------------------------------------------------------
/ssh/README.md:
--------------------------------------------------------------------------------
1 | # Karate and SSH
2 |
3 | Using the [Jsch](https://github.com/mwiede/jsch) Java library it is possible to open an SSH connection from Karate and send commands. This project provides a starting point and can be easily extended to return output to Karate for assertions or performing conditional logic.
4 |
5 | > Note that we use a fork of the popular [Jsch](http://www.jcraft.com/jsch) library which supports stricter security, needed by AWS EC2 instances for example.
6 |
7 | A test can be very simple as seen in [ssh.feature](src/test/java/karate/ssh.feature).
8 |
9 | Most of the work is handled by [`SshSession.java`](src/test/java/karate/SshSession.java). It takes care of opening a connection and returning an object (itself) that can be used to send command to the remote server.
10 |
11 | If you need more functionality, you can use the Karate core [Command](https://github.com/karatelabs/karate/blob/master/karate-core/src/main/java/com/intuit/karate/shell/Command.java) and [Console](https://github.com/karatelabs/karate/blob/master/karate-core/src/main/java/com/intuit/karate/shell/Console.java) classes as a reference to run a background thread, collect server output and make it available to the Karate / calling script.
12 |
13 | Please do consider improving this example and contributing code back to this project !
14 |
15 | ## Further Reading
16 | [Karate and CLI / Bash](../cli/README.md)
--------------------------------------------------------------------------------
/websocket/src/test/java/karate/stomp.feature:
--------------------------------------------------------------------------------
1 | Feature: tests the following spring-websocket example
2 | https://github.com/spring-guides/gs-messaging-stomp-websocket
3 |
4 | Background:
5 | * def result =
6 | """
7 | function(name) {
8 | var session = karate.get('session');
9 | var message = { command: 'SEND', headers: { destination: '/app/hello' }, body: { name: name } };
10 | session.send(message);
11 | var response = session.pop();
12 | return response.body.content;
13 | }
14 | """
15 |
16 | Scenario:
17 | * def session = karate.channel('websocket')
18 | * session.url = 'ws://localhost:8080/gs-guide-websocket'
19 | * def Adapter = Java.type('karate.StompAdapter')
20 | * session.adapter = new Adapter()
21 | * session.start()
22 | * session.send({ command: 'CONNECT', headers: { 'accept-version': '1.2', 'heart-beat': '0,0' } })
23 | * match session.pop() contains { command: 'CONNECTED' }
24 | * session.send({ command: 'SUBSCRIBE', headers: { id: 'sub-0', destination: '/topic/greetings' } })
25 |
26 | * match result('foo') == 'Hello, foo!'
27 | * match result('bar') == 'Hello, bar!'
28 |
29 | * session.send({ command: 'DISCONNECT', headers: { receipt: 'disc-0' } })
30 | * match session.pop() contains { command: 'RECEIPT', headers: { 'receipt-id': 'disc-0' } }
31 | * session.stop()
32 |
--------------------------------------------------------------------------------
/kafka/README.md:
--------------------------------------------------------------------------------
1 | # Karate Kafka
2 |
3 | Karate has native support for [Apache Kafka](https://kafka.apache.org) as an optional dependency (non-open source and commercial). Enterprise users can find more information here: [Karate-Kafka](https://github.com/karatelabs/karate-addons/tree/main/karate-kafka).
4 |
5 | A license is required for running (for e.g. in CI/CD) and a Karate Labs IDE subscription is required per developer seat.
6 |
7 | This sample project shows how to use the Avro and plain-JSON support. Make sure you have a `.karate/karate.lic` file in place before running the example.
8 |
9 | ## Running
10 | * Docker is required to start the Kafka broker and Zookeeper. There is a `docker-compose.yml` file in this project.
11 | * Run the following commands
12 | * `docker compose up -d`
13 | * `mvn test`
14 | * To stop the Docker containers run `docker compose down`
15 |
16 | ## Further Reading
17 | * [kafka-custom](../kafka-custom/README.md) - it is possible to test Kafka by writing the Java integration code yourself and generating Java code, but the approach above is recommended
18 | * [kafla-mtls](../kafka-mtls/README.md) - using MTLS (SSL / Auth) with Kafka and also includes an example of hybrid API + Kafka testing
19 | * [community-example](https://github.com/Sdaas/karate-kafka) - a community project that provides a generic approach to testing Kafka with Karate, but requires you to to write / generate Java code.
--------------------------------------------------------------------------------
/kafka/src/test/java/karate/kafka.feature:
--------------------------------------------------------------------------------
1 | Feature: karate-kafka demo
2 |
3 | Background:
4 | * configure kafka =
5 | """
6 | {
7 | 'bootstrap.servers': '127.0.0.1:29092',
8 | 'schema.registry.url': 'http://localhost:8081'
9 | }
10 | """
11 |
12 | Scenario:
13 | * def channel = karate.channel('kafka')
14 | * channel.register({ name: 'hello', path: 'classpath:karate/hello.avsc' })
15 |
16 | * def consumer = channel.consumer()
17 |
18 | * consumer.topic = 'test-topic'
19 | * consumer.count = 2
20 | * consumer.filter = x => x.key != 'zero'
21 | * consumer.timeout = 5000
22 | * consumer.start()
23 |
24 | * def producer = channel.producer()
25 |
26 | * producer.topic = 'test-topic'
27 | * producer.schema = 'hello'
28 | * producer.key = 'zero'
29 | * producer.value = { message: 'hello0', info: { first: 0, second: false } }
30 | * producer.send()
31 |
32 | * producer.headers = { foo: 'bar1', baz: 'ban1' }
33 | * producer.key = 'first'
34 | * producer.value = { message: 'hello1', info: { first: 1, second: true } }
35 | * producer.send()
36 |
37 | * producer.key = 'second'
38 | * producer.headers = null
39 | * producer.value = { message: 'hello2', info: { first: 2, second: false } }
40 | * producer.send()
41 |
42 | * def response = consumer.collect()
43 | * match response[0].key == 'first'
44 | * match response[0].headers == { foo: 'bar1', baz: 'ban1' }
45 | * match response[1].value == { message: 'hello2', info: { first: 2, second: false } }
--------------------------------------------------------------------------------
/kafka-mtls/README.md:
--------------------------------------------------------------------------------
1 | # Karate Kafka MTLS
2 |
3 | This is an additional example for [Karate Kafka](../kafka/README.md) that shows how to use MTLS and client-side authentication.
4 |
5 | This section of the test in [kafka-json.feature](src/test/java/karate/kafka-json.feature) sets up client-side SSL:
6 |
7 | ```cucumber
8 | * configure kafka =
9 | """
10 | {
11 | 'bootstrap.servers': 'localhost:29093',
12 | 'security.protocol': 'SSL',
13 | 'ssl.truststore.location': 'ssl/client.truststore.pkcs12',
14 | 'ssl.truststore.password': 'karate'
15 | }
16 | """
17 | ```
18 |
19 | Here the [docker-compose.yml](docker-compose.yml) configures Kafka to use SSL. This example does not use the schema registry.
20 |
21 | The certificates and related files in the [/ssl](ssl) folder were created using [conf/commands.txt](conf/commands.txt).
22 |
23 | ## Hybrid Test
24 | This example also contains an example of how to mix API and Kafka tests, which is a common scenario.
25 |
26 | Refer to [kafka-hybrid.feature](src/test/java/karate/kafka-hybrid.feature). Note how `karate.consume()` is called at the start of the test before any other actions.
27 |
28 | Commands were adapted from these references:
29 | * [Setting up Encryption](https://developer.confluent.io/courses/security/hands-on-setting-up-encryption)
30 | * [Encrypting Traffic](https://developer.confluent.io/courses/security/hands-on-requiring-encryption-for-broker-traffic/)
31 | * [GitHub Repo](https://github.com/confluentinc/learn-kafka-courses/tree/main/fund-kafka-security)
--------------------------------------------------------------------------------
/ssl/src/main/java/io/karatelabs/examples/ssl/TestService.java:
--------------------------------------------------------------------------------
1 | package io.karatelabs.examples.ssl;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6 | import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @Configuration
13 | @EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class, DataSourceAutoConfiguration.class})
14 | public class TestService {
15 |
16 | @RestController
17 | @RequestMapping("/test")
18 | class TestController {
19 |
20 | @GetMapping
21 | public String test() {
22 | return "{ \"success\": true }";
23 | }
24 |
25 | }
26 |
27 | public static void main(String[] args) {
28 | String[] customArgs = {
29 | "--server.port=8080",
30 | "--server.ssl.key-store=src/main/resources/server-keystore.p12",
31 | "--server.ssl.key-store-password=karate-mock",
32 | "--server.ssl.keyStoreType=PKCS12",
33 | "--server.ssl.keyAlias=karate-mock"};
34 | SpringApplication.run(TestService.class, customArgs);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/database/src/test/java/karate/DbUtils.java:
--------------------------------------------------------------------------------
1 | package karate;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.jdbc.core.JdbcTemplate;
8 | import org.springframework.jdbc.datasource.DriverManagerDataSource;
9 |
10 | public class DbUtils {
11 |
12 | private static final Logger logger = LoggerFactory.getLogger(DbUtils.class);
13 |
14 | private final JdbcTemplate jdbc;
15 |
16 | public DbUtils(Map config) {
17 | String url = (String) config.get("url");
18 | String username = (String) config.get("username");
19 | String password = (String) config.get("password");
20 | String driver = (String) config.get("driverClassName");
21 | DriverManagerDataSource dataSource = new DriverManagerDataSource();
22 | dataSource.setDriverClassName(driver);
23 | dataSource.setUrl(url);
24 | dataSource.setUsername(username);
25 | dataSource.setPassword(password);
26 | jdbc = new JdbcTemplate(dataSource);
27 | logger.info("init jdbc template: {}", url);
28 | }
29 |
30 | public Object readValue(String query) {
31 | return jdbc.queryForObject(query, Object.class);
32 | }
33 |
34 | public Map readRow(String query) {
35 | return jdbc.queryForMap(query);
36 | }
37 |
38 | public List