Skip to content

Commit

Permalink
Merge branch 'develop' into 2422-arm64-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas authored Jun 6, 2024
2 parents 26b87c9 + 233190b commit 5384f7f
Show file tree
Hide file tree
Showing 140 changed files with 2,157 additions and 1,482 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -71,6 +71,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
6 changes: 3 additions & 3 deletions .github/workflows/jdk-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
uses: oracle-actions/setup-java@v1
with:
website: jdk.java.net
release: 21
release: 23
- name: cache maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-
- name: build with maven
run: mvn -B clean install -P pre-release -pl '!karate-gatling' -Djavacpp.platform=linux-x86_64
run: mvn -B clean install -P pre-release -Djavacpp.platform=linux-x86_64
6 changes: 3 additions & 3 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
- name: git checkout
uses: actions/checkout@v4
- name: set up jdk 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 17
- name: cache maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand All @@ -31,7 +31,7 @@ jobs:
- name: upload workspace if build fails
# if: ${{ failure() }}
if: ${{ false }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-results
path: .
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ on:
workflow_dispatch:
inputs:
version:
description: version
required: true
default: 'X.X.X.RCX'
docker:
required: true
type: choice
options:
- 'enabled'
- 'disabled'

jobs:
build:
Expand All @@ -16,7 +21,7 @@ jobs:
- name: git checkout
uses: actions/checkout@v4
- name: set up jdk 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
java-version: 17
Expand All @@ -29,22 +34,25 @@ jobs:
run: |
mvn versions:set versions:commit -B -ntp -DnewVersion=${{ github.event.inputs.version }}
- name: docker build
if: ( github.event.inputs.docker == 'enabled' )
run: |
mvn clean install -B -ntp -DskipTests -P pre-release
./build-docker.sh
- name: docker login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
if: ( github.event.inputs.docker == 'enabled' )
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: docker push
if: ( github.event.inputs.docker == 'enabled' )
run: |
docker buildx build --push --platform linux/amd64 --cache-from=type=local,src=./target/docker -t karate-chrome -t karatelabs/karate-chrome:latest -t karatelabs/karate-chrome:${{ github.event.inputs.version }} karate-docker/karate-chrome
docker buildx build --push --platform linux/amd64,linux/arm64 --cache-from=type=local,src=./target/docker -t karate-chromium -t karatelabs/karate-chromium:latest -t karatelabs/karate-chromium:${{ github.event.inputs.version }} karate-docker/karate-chromium
- name: maven deploy to central
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USER }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
run: |
mvn -B -ntp deploy -DskipTests -P pre-release,release
Expand All @@ -53,7 +61,7 @@ jobs:
mvn package -DskipTests -P fatjar -f karate-core/pom.xml
mvn package -DskipTests -P fatjar -f karate-robot/pom.xml
- name: upload binaries
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: karate-release-${{ github.event.inputs.version }}
retention-days: 5
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</a>
</div>
<div>
<a href="https://central.sonatype.com/namespace/com.intuit.karate">
<img src="https://img.shields.io/maven-central/v/com.intuit.karate/karate-core.svg"/>
<a href="https://central.sonatype.com/namespace/io.karatelabs">
<img src="https://img.shields.io/maven-central/v/io.karatelabs/karate-core.svg"/>
</a>
<a href="https://github.com/karatelabs/karate/actions?query=workflow%3Amaven-build">
<img src="https://github.com/karatelabs/karate/actions/workflows/maven-build.yml/badge.svg?branch=develop"/>
Expand Down Expand Up @@ -1790,6 +1790,8 @@ This can be easily solved by using `java.math.BigDecimal`:
* match json == '{"num":123123123123}'
```

For more tips, refer [here](https://stackoverflow.com/a/77576066/143475).

## `doc`
Karate has a built-in HTML templating engine that can be used to insert additional custom HTML into the test-reports. Here is an [example](karate-core/src/test/java/com/intuit/karate/core/users-doc.feature):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Payment create(@RequestBody Payment payment) {
}

@PutMapping("/{id:.+}")
public Payment update(@PathVariable int id, @RequestBody Payment payment) {
public Payment update(@PathVariable("id") int id, @RequestBody Payment payment) {
payments.put(id, payment);
return payment;
}
Expand All @@ -55,7 +55,7 @@ public Collection<Payment> list() {
}

@GetMapping("/{id:.+}")
public Payment get(@PathVariable int id) {
public Payment get(@PathVariable("id") int id) {
Payment payment = payments.get(id);
if (payment == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
Expand All @@ -64,7 +64,7 @@ public Payment get(@PathVariable int id) {
}

@DeleteMapping("/{id:.+}")
public void delete(@PathVariable int id) {
public void delete(@PathVariable("id") int id) {
Payment payment = payments.remove(id);
if (payment == null) {
throw new RuntimeException("payment not found, id: " + id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature:

Scenario:
* print 'hello'
6 changes: 3 additions & 3 deletions examples/consumer-driven-contracts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.surefire.version>2.22.2</maven.surefire.version>
<spring.boot.version>2.3.4.RELEASE</spring.boot.version>
<spring.boot.version>3.2.2</spring.boot.version>
<junit5.version>5.7.0</junit5.version>
<karate.version>1.4.1</karate.version>
<java.version>17</java.version>
<karate.version>1.5.0.RC3</karate.version>
</properties>

<dependencies>
Expand Down
40 changes: 31 additions & 9 deletions karate-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| <a href="#karate-chrome">Docker / <code>karate-chrome</code></a>
| <a href="#driver-types">Driver Types</a>
| <a href="#playwright">Playwright</a>
| <a href="#playwright-legacy">Playwright Legacy</a>
| <a href="#timeout"><code>timeout()</code></a>
| <a href="#driversessionid"><code>driver.sessionId</code></a>
</td>
Expand Down Expand Up @@ -346,7 +347,36 @@ Note that some capabilities such as "headless" may be possible via the command-l

Also see [`driver.sessionId`](#driversessionid).


### Playwright

Driver that leverages [Playwright](https://playwright.dev) java native APIs.

To use it, add the following dependency:
```xml
<dependency>
<groupId>io.karate</groupId>
<artifactId>karate-playwright</artifactId>
<scope>test</scope>
</dependency>
```

And make sure it is declared before `io.karate:karate-core`.

A server will be automatically started and made available to Karate without any extra-script. If you have one pre-started, you can still use the [`playwrightUrl`](#configure-driver) driver config.

### `playwrightOptions`
When using [Playwright](#playwright) you can omit this in which case Karate will default to Chrome (within Playwright) and the default browser window size.

This can take the following keys:
* `browserType` - defaults to `chromium`, can be set to the other [types that Playwright supports](https://playwright.dev/docs/core-concepts#browser), e.g. `firefox` and `webkit`
* `context` - JSON which will be passed as the argument of the Playwright [`browser.newContext()`](https://playwright.dev/docs/api/class-browser#browsernewcontextoptions) call, needed typically to set the page dimensions
* `channel` - defaults to chrome, for the `chromium` browserType, allows to specify which [flavor](https://playwright.dev/docs/browsers#google-chrome--microsoft-edge) to use
* `installBrowsers` - defaults to `true`, whether or not all the supported browsers will be downloaded and installed by Playwright (once).

Note that there is a top-level config flag for `headless` mode. The default is: `* configure driver = { headless: false }`

### Playwright Legacy
To use [Playwright](https://playwright.dev), you need to start a Playwright server. If you have one pre-started, you need to use the [`playwrightUrl`](#configure-driver) driver config.

Or you can set up an executable that can do it and log the URL to the console when the server is ready. The websocket URL will look like this: `ws://127.0.0.1:4444/0e0bd1c0bb2d4eb550d02c91046dd6e0`.
Expand Down Expand Up @@ -399,14 +429,6 @@ For convenience, Karate assumes by default that the executable name is `playwrig

Based on the above details, you should be able to come up with a custom strategy to connect Karate to Playwright. And you can consider a [`driverTarget`](#custom-target) approach for complex needs such as using a Docker container for CI.

### `playwrightOptions`
When using [Playwright](#playwright) you can omit this in which case Karate will default to Chrome (within Playwright) and the default browser window size.

This can take the following keys:
* `browserType` - defaults to `chromium`, can be set to the other [types that Playwright supports](https://playwright.dev/docs/core-concepts#browser), e.g. `firefox` and `webkit`
* `context` - JSON which will be passed as the argument of the Playwright [`browser.newContext()`](https://playwright.dev/docs/api/class-browser#browsernewcontextoptions) call, needed typically to set the page dimensions

Note that there is a top-level config flag for `headless` mode. The default is: `* configure driver = { headless: false }`

## `configure driverTarget`
The [`configure driver`](#configure-driver) options are fine for testing on "`localhost`" and when not in `headless` mode. But when the time comes for running your web-UI automation tests on a continuous integration server, things get interesting. To support all the various options such as Docker, headless Chrome, cloud-providers etc., Karate introduces the concept of a pluggable [`Target`](src/main/java/com/intuit/karate/driver/Target.java) where you just have to implement two methods:
Expand Down Expand Up @@ -1950,7 +1972,7 @@ Scenario:
* screenshot()
```

* `driver.intercept()` is supported only for the driver type `chrome`
* `driver.intercept()` is fully supported only for the driver type `chrome`. [`Playwright`](#playwright) supports only [urlPatterns](https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#type-RequestPattern)
* you can route multiple URL patterns to the same Karate mock-feature, the format of each array-element under `patterns` can be found [here](https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#type-RequestPattern).
* the `*` wildcard (most likely what you need) will match any number of characters, e.g. `*myhost/some/path/*`
* `?` will match any single character
Expand Down
Loading

0 comments on commit 5384f7f

Please sign in to comment.