I have the following scenario that matches the response against a multi-line expression that contains a variable. This variable is defined in karate-config.js
and is present because the test succeeds up to the final step.
Background:
Given url $baseUrl
Scenario: Fetch Root
Given path "/"
When method GET
Then status 200
And match header Content-Type == $halJson
And match response ==
"""
{
"_links": {
"user": {
"href": "$baseUrl/user"
}
}
}
"""
How can I get the baseUrl
variable replaced with the real value in the match response
step?
In Python, you have different ways to specify a multiline string. You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python.
A multiline string is a string whose value exceeds beyond one line. In that, the string should be enclosed within a here-string(@””@). Newline or carriage return value can also be used to create a multiline string. Multiline string can also be defined by using a line break within double-quotes.
With the help of a co-worker I found something that worked
And match response ==
"""
{
"_links": {
"fpu": {
"href": '#(baseUrl + "/fpu")'
}
}
}
"""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With