Skip to content

Commit fde2e7c

Browse files
authored
Update docs on Karate usage (#85)
* Note on building JSON payloads in Karate * How to pass additional environment variables to tests * Add new namespaces
1 parent 2051595 commit fde2e7c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ And request { name: 'Billie', color: 'black' }
274274
And request karate.readAsString('../fixtures/example.ttl')
275275
```
276276
277+
Since Karate has special handling of JSON you need to be careful when passing JSON which includes local variables in the
278+
request. You can either use `#()` to embed an expression or wrap the whole JSON object in `()` so that it is treated as
279+
Javascript and not processed by Karate. Also be aware that when sending JSON-LD you need to wrap any keywords in quotes.
280+
Both of the following approaches will work but the first is preferred as it is more obvious:
281+
```gherkin
282+
* def url = 'http://localhost/test'
283+
And request {@context: ['https://www.w3.org/ns/solid/notification/v1'], type: 'WebSocketSubscription2021', topic: '#(url)'}
284+
And request ({'@context': ['https://www.w3.org/ns/solid/notification/v1'], type: 'WebSocketSubscription2021', topic: url})
285+
```
286+
277287
### Sending the request
278288
The HTTP request is sent when you use the `method` keyword and a specific method. You would normally use this in
279289
conjunction with the `When` keyword:
@@ -375,6 +385,17 @@ Within a test case, you have access to the Karate object which has a number of u
375385
[here](https://karatelabs.github.io/karate/#the-karate-object). This includes methods to manipulate data, call functions
376386
with a lock so they only run once, read from files, create loops, and handle async calling.
377387
388+
You can also access additional environment values using `karate.properties['OPTION']` where the values are defined in
389+
your environment files using `JAVA_TOOL_OPTIONS`. For example:
390+
```shell
391+
JAVA_TOOL_OPTIONS=-Dproperty1=value1 -Dproperty2=value2
392+
```
393+
You should confirm the value is set before tests continue:
394+
```gherkin
395+
* def externalProperty = karate.properties['property1']
396+
* match externalProperty == '#notnull'
397+
```
398+
378399
## Calling Functions
379400
See https://karatelabs.github.io/karate/#code-reuse--common-routines
380401
@@ -466,7 +487,7 @@ The test harness makes some variables available to all tests:
466487
`bob`. One of these clients will need to be passed to any newly created `SolidContainer` or `SolidResource` - The user
467488
names are the key (e.g., `clients.alice`).
468489
* `webIds` - An object containing the webIds of the 2 users. These are needed when setting up ACLs (e.g., `webIds.alice`).
469-
* `RDF`, `XSD`, `LDP`, `ACL`, `FOAF`, `ACP` - Namespaces for use when constructing IRIs.
490+
* `RDF`, `XSD`, `LDP`, `ACL`, `FOAF`, `ACP`, `SOLID`, `NOTIFY`, `PROV`, `AS` - Namespaces for use when constructing IRIs.
470491
471492
## Helper Functions
472493
@@ -1337,4 +1358,4 @@ The release process is:
13371358
* Choose the tag that was just created.
13381359
* Add a title, e.g. `Release 1.0.0`.
13391360
* Add some content describing notable changes.
1340-
* Publish the release.
1361+
* Publish the release.

0 commit comments

Comments
 (0)