-
-
Notifications
You must be signed in to change notification settings - Fork 374
YAML DSL For Test Scenarios
Sometimes testers or developers need to describe their automation scenarios in YAML format. Zerocode provides the mechanism to achieve this using YAML.
For example, if we have an GET
API /api/v1/search/persons
which returns the Http status as 200
and the below response payload,
{
"exactMatches": true,
"name": "Mr Bean",
"city": "Lon"
}
then we can write the automation Test-case as below.
---
scenarioName: As simple GET request response
steps:
- name: "find_match"
url: "/api/v1/search/persons"
operation: "GET"
request:
queryParams:
lang: "Amazing"
city: "Lon"
verifications:
status: 200
body:
exactMatches: true
name: "Mr Bean"
city: "Lon"
Where
-
scenarioName
: Unique Free text string describing precisely what is being tested -
name
: Unique name of this step wrt this scenario -
url
: Relative URL path or FQDN of the API end points -
operation
: An http operation e.g. GET, POST, PUT, DELETE, HEAD etc -
request
: The requestpayload
with httpheaders
and/orquery parameters
-
verifications
: The expected http status and response payload -
status
: An http status code e.g. 200 is OK, 201 is CREATED etc.
The JSON Path can be used to pick an element/field and reuse it in subsequent steps.
In the below test scenario, please have a look at the 2nd step's verifications
block where various JSON Paths are used to pick/reuse the desired fields rather than hard-coded values.
---
scenarioName: As simple GET request response Multi STep
steps:
- name: find_match
url: "/api/v1/search/persons"
operation: GET
request:
queryParams:
lang: Amazing
city: Lon
assertions:
status: 200
body:
exactMatches: true
name: Mr Bean
lang: Amazing
city: Lon
- name: find_match2
url: "/api/v1/search/persons"
operation: GET
request:
queryParams:
lang: Amazing
city: Lon
verifications:
status: "$EQ.${$.find_match.response.status}"
body:
exactMatches: true
name: "$CONTAINS.STRING:Bean"
lang: "${$.find_match.response.body.lang}"
city: "${$.find_match2.request.queryParams.city}"
e.g. the API responds with a person
payload with array of addresses
.
In an YAML file if the line starts with a
-
mark, then the containing element is anarray
.
---
scenarioName: "A simple GET API Scenario" #comments allowed
steps:
- name: "find_match"
url: "/api/v1/persons/p001"
operation: "GET"
request:
headers:
x-api-key: "Ama-zing-key"
x-api-secret: "Sec-ret-stuff"
verifications:
status: 200 #comment - a http status code as int value
body:
exactMatches: true
name: "Mr Bean"
addresses:
- type: "office"
line1: "10 Random St"
- type: "home"
line1: "300 Random St"
Here addresses
in the response body
is a collection of individual address.
The equivalent JSON looks like below.
{
"addresses": [
{
"type": "office",
"line1": "10 Random St"
},
{
"type": "home",
"line1": "300 Random St"
}
]
}
We can find the examples in the HelloWorld GitHub repo under yaml
folder.
Visit the Zerocode Documentation Site for all things.
-
User's Guide
-
Matchers
-
Zerocode Value Tokens
-
YAML DSL
-
Http Testing
-
Kafka Testing
- Introduction
- Produce, consume proto message
- Produce raw message
- Consume raw message
- Produce JSON message
- Consume JSON message
- Produce and consume XML message
- Kafka - consume the latest message or n latest messages
- Produce avro message
- Consume avro message
- KSQL in action
- Produce multiple records
- Produce from file
- Produce to a partition
- Produce and consume records with headers
- Produce n assert partition ack
- Comsume and dump to file
- commitSync vs commitAsync
- Overriding config inside a test
- Chosing String or Int or Avro Serializer
- Chosing String or Int or Avro Deserializer
- Attaching timestamp during load
- Default timestamp provided by Kafka
- Consume and assert avro schema metadata
- Error handling - produce via avro schema
- Sorting Kafka records consumed
-
DB Testing
-
Kotlin Testing
-
Performance Testing - Load and Stress
- Performance Testing - via awesome JUnit runners
- Load Vs Stress generation on target application
- Run a single test or a scenario in parallel
- Run multiple test scenarios in parallel - Production load simulation
- Dynamically change the payload for every request
- Analytics - Useful report(s) or statistics
-
Parameterized Testing
-
Docker
-
More+
-
Extensions
-
JUnit5 Jupiter Test
-
Questions And Answers(FAQ)
- What is Zerocode testing?
- SSL http https connections supported?
- How to assert array size Greater-Than Lesser-Than etc?
- How to invoke POST api?
- How to assert custom headers of the response?
- How to pass custom security token into the request header?
- When to use JUnit Suite runner and when Zerocode Package runner?
- How to execute DB SQL and assert?
- How to handle Http response other than utf-8 e.g. utf-16 or utf-32 ?
- Random Number Generator Placeholders Usages and Limits
- Automation tests for Zerocode lib itself
- Picking a leaf value from the array matching JSON Path
- Array assertions made easy, incl. size and element finder
-
Read Our Blogs
- Top 16 Open Source API Testing Tools For REST & SOAP Services - joecolantonio (Lists popular tools - Globally)
- OAuth2 Test Automation - DZone 2min Read
- Zero defect APIs - Build Pipe Line - Medium 10 min Read
- Develop ZeroDefect API's with ZeroCode! - Extreme Portal ( A must read for all developers and test engineers) 10min Read
- Performance testing using JUnit and maven - Codeproject 10 min Read
- REST API or SOAP End Point Testing - Codeproject 10min Read
- DZone- MuleSoft API Testing With Zerocode Test Framework - DZone 5min Read
- Testing need not be harder or slower, it should be easier and faster - DZone 5 min Read
- Kotlin Integration Testing simplified via Zerocode - Extreme portal 10 min Read
- and More...