Using Tavern and trying to run tavern-ci against this yaml:
test_name: tavern poc
- name: list
request:
url: https://xxx.xxx.xxx.us/api/v3/institutions/
method: GET
response:
status_code: 200
headers:
content-type: application/json
save:
body:
content: content
Am getting
E ScannerError: mapping values are not allowed here
E in "/Users/xxx/xxx/xxx/test_poc.tavern.yaml", line 3, column 9
Have tried many of the solutions presented here (most of which are 'put a space after the colon') without joy.
Yamllint gives the same error...
At the root of your YAML document you have a mapping with key test_name and as value the start of a plain scalar tavern .....
The parser expects a key, with the same indent as the first line, on the second line or a continuation of your plain scalar from the first line. The second line is empty, so it continues with the same expectations on the third line. There it finds an - which is further indented than the beginning of test_name, so it is not a key, but part of the plain scalar. Then it finds name also part of a the plain scalar started on the first line and then : (colon + space).
But that colon+space is not allowed in plain scalar, as that gives potential ambiguity with the start of another key-value pair.
The unlikely solution is that you put double quotes before tavern and at the end of the YAML document.
More likely you should include a key for which the structure starting with - name: list this is the value. E.g.:
test_name: tavern poc
stages:
- name: list
request:
(as from the second entry you get from googling "tavern yaml")
Related
Sometimes, when processing log events in vector, a log source might have hyphens as key names - for example json structured logs. Assuming it is from a third party and changing them there is not an option, how can we handle these keys?
A sample log message (contrived for demonstration) is:
{
"labels":{"no_hypens":"normal field","this-has-hypens":"this is a test"},
"message":"a message",
"timestamp":"2022-11-01T12:03:00.941866394Z"
}
Note the field labels.this-has-hyphens there.
I managed to put together a test case, and find out the syntax, both in providing test data like this and in extracting the data in VRL:
The test case
---
tests:
- name: hypens
inputs:
- insert_at: hypens
type: log
log_fields:
labels."this-has-hypens": "this is a test"
labels.no_hypens: "normal field"
outputs:
- extract_from: hypens
conditions:
- type: vrl
source: |
assert_eq!("normal field", .no_hypens)
assert_eq!("this is a test", .output_without_hypens)
This will insert and check for two fields from the input data. Note the hyphenated key segment needs to be quoted.
Next the VRL in the transform:
---
transforms:
hypens:
type: remap
inputs:
- route
source: |
log(., "error")
. = {
"no_hypens": .labels.no_hypens,
"output_without_hypens": .labels."this-has-hypens",
}
The log message is there as while debugging this, I had to figure out that the test hyphenated field didn't even get to the transform until I had quotes around it.
Then the field reference itself needs to have quotes too, after the dot (not square brackets).
This will pass the tests, and output the right data.
I am getting a response in form of serialized json format for an api request as below
{"Data":"{\"orderId\":null,\"Tokens\":{\"Key\":\"abcdefgh123456\",\"Txnid\":\"test_5950\"}","success":true,"Test":"success"}
I want to extract Key value in Jmeter and I have to use into next request. Can someone help me on extracting the value?
Your JSON seems incorrect. The valid JSON should be like:
{
"Data":{
"orderId":null,
"Tokens":{
"Key":"abcdefgh123456",
"Txnid":"test_5950"
},
"success":true,
"Test":"success"
}
}
Add a JSON Extractor to the request from where you want to extract the Key value.
assign a variable name, i.e key
JSON Path Expression will be : .Data.Tokens.Key
use the extracted value as ${key} into the next request.
If your JSON really looks exactly like you posted the most suitable Post-Processor would be Regular Expression Extractor
The relevant regular expression would be something like:
"Key"?\s*:?\s*"(\w+)"
where:
``?\s*` - arbitrary number of whitespaces (just in case)
\w - matches "word" character (alphanumeric plus underscores)
+ - repetition
() - grouping
More information:
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet
JMeter: Regular Expressions
In the OpenApi3-spec of my API I have an endpoint returning CSV-data. No my Dredd-Test fails although example and returned are exactly the same. I assume the problem that my API returns CSV with a BOM character.
Now I have no idea How I can encode the character correctly in OpenAPI3-YAML. Can anyone help me out?
I tried \ufeff as I would do in JSON but it didn't work.
responses:
"200":
description: ffffoo
content:
text/csv;charset=UTF-8:
schema:
type: string
example: |-
a;b;c
1;2;3
4;5;5
A literal block scalar does not process escape sequences, you'll need a double-quoted scalar for that:
responses:
"200":
description: ffffoo
content:
text/csv;charset=UTF-8:
schema:
type: string
example: "\ufeff\
a;b;c\n\
1;2;3\n\
4;5;5"
An escaped line break excludes the line break from the content. Unescaped line breaks in double-quoted scalars would be folded into an undesired space. \n\ basically replaces the space that would be generated from the line break with a proper line break.
You can of course do away with the line breaks in the source but I'd say this is more readable.
The problem that I am facing is the following:
I have the following lines in my vars:
testparams:
- { name: 'test' , test_type: 'test' }
What I need to do, from my tasks, is to include a file when this dictionary is defined. This is my code:
- include: test.yml
when: testparams is defined
It works when the whole definition of the dictionary is absent. But, when the dictionary definition is there but without any elements inside, this condition fails. I have tried with length, trying to get the type(just run it when it's Dictionary), but everything has failed so far.
Example of defined dictionary without elements:
testparams:
Any ideas?
The definition of an empty list is done with brackets like in the following example:
testparams: []
And in your case, I would use the following test to have it work in all conditions:
when: testparams | default([]) | length > 0
Be aware that you are still responsible to sanitize your testparams definition as this might break if:
you define a list of testparams that does not have the correct values
you define testparams as a non empty string (which also has a length > 0).
The response I get back from a post is just a plain text guid seen here I'd like to pull this guid and use it in a variable for my following Get statement:
post response data
And I've tried a bunch of configurations in my regular expression extractor.
But it just ends up pulling Null when what I want is that guid.
Null
I'm new to jmeter - so thank you in advance for the help.
If you need the whole response use the following Regular Expression Extractor configuration:
Reference Name: response
Regular Expression: (?s)(^.*)
Template: $1$
As per How to Extract Data From Files With JMeter guide:
() = grouping
(?s) = single line modifier
^ = line start
. = wild-card character
* = repetition
So it will return the whole response.