You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| [Data Driven Tests](#data-driven-tests) | [Auth](#sign-in-example) and [Headers](#http-basic-authentication-example) | [Dynamic Port Numbers](#dynamic-port-numbers)
55
+
| [Data Driven Tests](#data-driven-tests) | [Auth](#sign-in-example) and [Headers](#http-basic-authentication-example) | [Dynamic Port Numbers](#dynamic-port-numbers) | [Ignore / Vallidate](#ignore-or-validate)
56
56
57
57
# Features
58
58
* Scripts are plain-text files and require no compilation step or IDE
@@ -162,7 +162,7 @@ This is all that you need within your `<dependencies>`:
162
162
<dependency>
163
163
<groupId>com.intuit.karate</groupId>
164
164
<artifactId>karate-core</artifactId>
165
-
<version>0.1.4</version>
165
+
<version>0.1.5</version>
166
166
<scope>test</scope>
167
167
</dependency>
168
168
```
@@ -178,7 +178,7 @@ You can replace the values of 'com.mycompany' and 'myproject' as per your needs.
178
178
mvn archetype:generate \
179
179
-DarchetypeGroupId=com.intuit.karate \
180
180
-DarchetypeArtifactId=karate-archetype \
181
-
-DarchetypeVersion=0.1.4 \
181
+
-DarchetypeVersion=0.1.5 \
182
182
-DgroupId=com.mycompany \
183
183
-DartifactId=myproject
184
184
```
@@ -516,10 +516,10 @@ no need to compile Java code any more.
516
516
517
517
-| Cucumber | Karate
518
518
------ | -------- | ------
519
-
**Must Add Step Definitions** | Yes. You need to keep implementing them as your functionality grows. [This can get very tedious](https://angiejones.tech/rest-assured-with-cucumber-using-bdd-for-web-services-automation#comment-40). | No.
520
-
**Layers of Code to Maintain** | **2**: Gherkin (custom grammar), and corresponding Java step-definitions | **1**: Karate DSL
521
-
**Natural Language** | Yes. Cucumber will read like natural language if you implement the step-definitions right. | No. Although Karate is a [true DSL](https://ayende.com/blog/2984/dsl-vs-fluent-interface-compare-contrast), it is ultimately a mini-programming language, although a very simple one. But for testing web-services at the level of HTTP requests and responses, it is ideal. Keep in mind that web-services are not 'human-facing' by design.
522
-
**BDD Syntax** | Yes | Yes
519
+
**More Step Definitions Needed** | **Yes**. You need to keep implementing them as your functionality grows. [This can get very tedious](https://angiejones.tech/rest-assured-with-cucumber-using-bdd-for-web-services-automation#comment-40). | **No**.
520
+
**Layers of Code to Maintain** | **2**Layers. One is the Gherkin custom grammar for your business domain, and you will also have the corresponding Java step-definitions. | **1**Layer. Just Karate-script, and no Java code needs to be implemented.
521
+
**Natural Language** | **Yes**. Cucumber will read like natural language if you implement the step-definitions right. | **No**. Although Karate is simple, and a [true DSL](https://ayende.com/blog/2984/dsl-vs-fluent-interface-compare-contrast), it is ultimately a mini-programming language. But for testing web-services at the level of HTTP requests and responses - it is ideal.
522
+
**BDD Syntax** | **Yes** | **Yes**
523
523
524
524
One nice thing about the design of the underlying Cucumber framework is that
525
525
script-steps are treated the same no matter whether they start with the keyword
@@ -622,7 +622,7 @@ the elegance of JSON to express complex nested data - while at the same time bei
622
622
able to dynamically plug values (that could be also JSON trees) into a JSON 'template'.
623
623
624
624
The [GraphQL / RegEx Replacement example](#graphql--regex-replacement-example) also demonstrates the usage
625
-
of 'embedded expressions', e.g.`'#(query)'`.
625
+
of 'embedded expressions', look for:`'#(query)'`.
626
626
627
627
### Multi-Line Expressions
628
628
The keywords [`def`](#def), [`set`](#set), [`match`](#match) and [`request`](#request) take multi-line input as
@@ -700,11 +700,11 @@ function(s) {
700
700
If you want to do advanced stuff such as make HTTP requests within a function -
701
701
that is what the [`call`](#call) keyword is for.
702
702
703
-
[More examples](#calling-java) of calling Java appear later in this document.
703
+
[More examples](#calling-java) of calling Java appear later on in this document.
704
704
705
705
## Reading Files
706
706
This actually is a good example of how you could extend Karate with custom functions.
707
-
`read()` is a JavaScript function that is automatically available when Karate starts.
707
+
The variable `read` is a JavaScript function that is automatically available when Karate starts.
708
708
It takes the name of a file as the only argument.
709
709
710
710
By default, the file is expected to be in the same folder (package) as the *.feature file.
@@ -884,7 +884,7 @@ When multipart post
884
884
Then status 201
885
885
```
886
886
887
-
# Multipartand SOAP
887
+
# Multipart, SOAP and SSL
888
888
## `multipart post`
889
889
Since a multipart request needs special handling, this is a rare case where the
890
890
[`method`](#method) step is not used to actually fire the request to the server. The only other
@@ -911,6 +911,7 @@ And match response /Envelope/Body/QueryUsageBalanceResponse == read('expected-re
911
911
## `ssl enabled`
912
912
This switches on Karate's support for making HTTPS calls without needing to configure a trusted certificate
913
913
or key-store. It is recommended that you do this at the start of your script or in the `Background:` section.
914
+
This built-in 'relaxed' mode is not enabled by default.
914
915
```cucumber
915
916
* ssl enabled
916
917
```
@@ -994,15 +995,17 @@ Setting values on JSON documents is simple using the `set` keyword and JSON-Path
> TODO: XML `set` support is limited to text-content and xml-attributes as of now
999
-
(not XML chunks).
1000
998
999
+
XML and XPath works just like you'd expect.
1001
1000
```cucumber
1002
-
# xml set
1003
1001
* def cat = <cat><name>Billie</name></cat>
1004
1002
* set cat /cat/name = 'Jean'
1005
1003
* match cat / == <cat><name>Jean</name></cat>
1004
+
1005
+
# you can even set whole fragments of xml
1006
+
* def xml = <foo><bar>baz</bar></foo>
1007
+
* set xml/foo/bar = <hello>world</hello>
1008
+
* match xml == <foo><hello>world</hello></foo>
1006
1009
```
1007
1010
1008
1011
## Ignore or Validate
@@ -1160,7 +1163,7 @@ When you use Karate, all your data assertions can be done in pure JSON and witho
1160
1163
forest of companion Java objects. And when you [`read`](#read) your JSON objects from (re-usable) files,
1161
1164
even complex response payload assertions can be accomplished in just a single line of Karate-script.
1162
1165
1163
-
## Matching All Array Elements
1166
+
## Validate every element in a JSON array
1164
1167
### `match each`
1165
1168
Karate has syntax sugar that can iterate over all elements in a JSON array. Here's how it works:
1166
1169
```cucumber
@@ -1375,7 +1378,7 @@ special object in a variable named: `karate`. This provides the following metho
1375
1378
*`url`: URL of the HTTP call to be made
1376
1379
*`method`: HTTP method, can be lower-case
1377
1380
*`body`: JSON payload
1378
-
*`karate.set(key, value)` - set the value of a variable immediately, which ensures that the [`headers`](#headers) routine for any HTTP calls made before this JavaScript function exits - works as expected
1381
+
*`karate.set(key, value)` - set the value of a variable immediately, which ensures that any active [`headers`](#headers) routine does the right thing for future HTTP calls (even those made by this function)
1379
1382
*`karate.get(key)` - get the value of a variable by name, if not found - this returns `null` which is easier to handle in JavaScript (than `undefined`)
1380
1383
*`karate.log(... args)` - log to the same logger being used by the parent process
1381
1384
*`karate.env` - gets the value (read-only) of the environment setting 'karate.env' used for bootstrapping [configuration](#configuration)
@@ -1404,7 +1407,8 @@ Either - it can be assigned to a variable like so.
1404
1407
Or - if a `call` is made without an assignment, and if the function returns a map-like
1405
1408
object, it will add each key-value pair returned as a new variable into the execution context.
1406
1409
```cucumber
1407
-
# while this looks innocent, behind the scenes it could be creating (or over-writing) lots of variables !
1410
+
# while this looks innocent ...
1411
+
# ... behind the scenes, it could be creating (or over-writing) a bunch of variables !
1408
1412
* call someFunction
1409
1413
```
1410
1414
While this sounds dangerous and should be used with care (and limits readability), the reason
@@ -1418,7 +1422,7 @@ You can invoke a function in a [re-usable file](#reading-files) using this short
1418
1422
### HTTP Basic Authentication Example
1419
1423
This should make it clear why Karate does not provide 'out of the box' support for any particular HTTP authentication scheme.
1420
1424
Things are designed so that you can plug-in what you need, without needing to compile Java code. You get to choose how to
1421
-
manage the environment-specific configuration values such as user-names and passwords.
1425
+
manage your environment-specific configuration values such as user-names and passwords.
1422
1426
1423
1427
First the JavaScript file, `basic-auth.js`:
1424
1428
```javascript
@@ -1490,12 +1494,13 @@ function() {
1490
1494
1491
1495
## GraphQL / RegEx replacement example
1492
1496
As a demonstration of Karate's power and flexibility, here is an example that reads a
1493
-
GraphQL string (which could be from a file) and modifies it to build custom queries
1497
+
GraphQL string (which could be from a file) and manipulates it to build custom dynamic queries
1494
1498
and filter criteria.
1495
1499
1496
1500
Once the function is declared, observe how calling it and performing the replacement
1497
1501
is an elegant one-liner.
1498
1502
```cucumber
1503
+
# this function would normally reside in a file
1499
1504
* def replacer =
1500
1505
"""
1501
1506
function(args) {
@@ -1509,14 +1514,23 @@ function(args) {
1509
1514
return query;
1510
1515
}
1511
1516
"""
1512
-
# in real life this line would likely read from a file
0 commit comments