additional "/" (slash) from response assertion is showing in Jmeter - jmeter

I want to use response assertion to match the response from server, here when I am getting responses it shows like {
"per_page": 6,
"total": 12,
"data": [
{
"last_name": "Lawson",
"id": 7,
"avatar": "https://reqres.in/img/faces/7-image.jpg",
"first_name": "Michael",
"email": "michael.lawson#reqres.in"
},
But in response assertion it showing like
Assertion failure message:Test failed: text expected to contain /{
"per_page": 6,
"total": 12,
"data": [
{
"last_name": "Lawson",
"id": 7,
"avatar": "https://reqres.in/img/faces/7-image.jpg",
"first_name": "Michael",
"email": "michael.lawson#reqres.in"
},
{
and therefor it gets failing even though its matching but due to addition / (slash), its getting failed.

JMeter doesn't "add" slashes anywhere, it's just a matter of visualization, you're getting your pattern surrounded with slashes as there is a mismatch, basically JMeter fails to find what you put in the "Patterns to test" in the application response
Demo:
See lines 472 and 480 in the ResponseAssertion source
So make sure that your response contains the pattern and be aware that every line brake or empty space matters so if your server returns non-formatted string and you're expecting a "pretty" one - the assertion will fail.
We cannot suggest the best option without seeing you actual response, however full-text comparing 2 JSON entities doesn't seem a good approach to me in terms of robustness and reliability, you might want to consider JSON Assertion or JSON JMESPath Assertion instead

Related

Azure Data Factory REST API paging with Elasticsearch

During developing pipeline which will use Elasticsearch as a source I faced with issue related paging. I am using SQL Elasticsearch API. Basically, I've started to do request in postman and it works well. The body of request looks following:
{
"query":"SELECT Id,name,ownership,modifiedDate FROM \"core\" ORDER BY Id",
"fetch_size": 20,
"cursor" : ""
}
After first run in response body it contains cursor string which is pointer to next page. If in postman I send the request and provide cursor value from previous request it return data for second page and so on. I am trying to archive the same result in Azure Data Factory. For this I using copy activity, which store response to Azure blob. Setup for source is following.
copy activity source configuration
This is expression for body
{
"query": "SELECT Id,name,ownership,modifiedDate FROM \"#{variables('TableName')}\" WHERE ORDER BY Id","fetch_size": #{variables('Rows')}, "cursor": ""
}
I have no idea how to correctly setup pagination rule. The pipeline works properly but only for the first request. I've tried to setup Headers.cursor and expression $.cursor but this setup leads to an infinite loop and pipeline fails with the Elasticsearch restriction.
I've also tried to read document at https://learn.microsoft.com/en-us/azure/data-factory/connector-rest#pagination-support but it seems pretty limited in terms of usage examples and difficult for understanding.
Could somebody help me understand how to build the pipeline with paging abilities utilization?
Responce with the cursor looks like:
{
"columns": [
{
"name": "companyId",
"type": "integer"
},
{
"name": "name",
"type": "text"
},
{
"name": "ownership",
"type": "keyword"
},
{
"name": "modifiedDate",
"type": "datetime"
}
],
"rows": [
[
2,
"mic Inc.",
"manufacture",
"2021-03-31T12:57:51.000Z"
]
],
"cursor": "g/WuAwFaAXNoRG5GMVpYSjVWR2hsYmtabGRHTm9BZ0FBQUFBRUp6VGxGbUpIZWxWaVMzcGhVWEJITUhkbmJsRlhlUzFtWjNjQUFBQUFCQ2MwNWhaaVIzcFZZa3Q2WVZGd1J6QjNaMjVSVjNrdFptZDP/////DwQBZgljb21wYW55SWQBCWNvbXBhbnlJZAEHaW50ZWdlcgAAAAFmBG5hbWUBBG5hbWUBBHRleHQAAAABZglvd25lcnNoaXABCW93bmVyc2hpcAEHa2V5d29yZAEAAAFmDG1vZGlmaWVkRGF0ZQEMbW9kaWZpZWREYXRlAQhkYXRldGltZQEAAAEP"
}
I finally find the solution, hopefully, it will be useful for the community.
Basically, what needs to be done it is split the solution into four steps.
Step 1 Make the first request as in the question description and stage file to blob.
Step 2 Read blob file and get the cursor value, set it to variable
Step 3 Keep requesting data with a changed body
{"cursor" : "#{variables('cursor')}" }
Pipeline looks like this:
pipeline
Configuration of pagination looks following
pagination . It is a workaround as the server ignores this header, but we need to have something which allows sending a request in loop.

Filter video list by tag

Goal
Get videos, ordered by date, and filtered by tag from a specific YouTube channel. I need only the videos that have that unique tag. I understand I can get the latest uploaded videos, then one by one query YouTube API for each video and determine if it has the tags I need. But I find that too lengthy and wonder if there's a single API request than can handle that filter for me.
Tried
Reading this API documentation I understood the snippet was supposed to have a snippet.tags:
snippet.tags[]
list
A list of keyword tags associated with the video. Tags may contain spaces. The property value has a maximum length of 500 characters. Note the following rules regarding the way the character limit is calculated:
The property value is a list, and commas between items in the list count toward the limit.
If a tag contains a space, the API server handles the tag value as though it were wrapped in quotation marks, and the quotation marks count toward the character limit. So, for the purposes of character limits, the tag Foo-Baz contains seven characters, but the tag Foo Baz contains nine characters.
Using the following (search/list)
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=CHANNEL_ID&maxResults=10&order=date&type=video&key=MY_GOOGLE_CONSOLE_KEY
I get:
{
"kind": "youtube#searchResult",
"etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/MO86DiShKKJ483oXkFJdDmvBd5M\"",
"id": {
"kind": "youtube#video",
"videoId": "jMywJTXhkVs"
},
"snippet": {
"publishedAt": "2017-09-16T15:28:40.000Z",
"channelId": "UC4GRKWUEhUvsCqD-yNQpxQw",
"title": "Real Time - Gesture Drawing 7 (5.10 mins time)",
"description": "Join me in gesture drawing practice from photo reference. :) References (in order of drawing) - Thank you to SenshiStock (https://senshistock.deviantart.com/) ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/jMywJTXhkVs/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/jMywJTXhkVs/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/jMywJTXhkVs/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Chayemor",
"liveBroadcastContent": "none"
}
}
The snippet only includes publishedAt, channelId, title, and description, certainly no tags.
Looking into /search/list documentation I see that it has another parameter that I might be able to use:
q
string
The q parameter specifies the query term to search for.
Your request can also use the Boolean NOT (-) and OR (|) operators to
exclude videos or to find videos that are associated with one of
several search terms. For example, to search for videos matching
either "boating" or "sailing", set the q parameter value to
boating|sailing. Similarly, to search for videos matching either
"boating" or "sailing" but not "fishing", set the q parameter value to
boating|sailing -fishing. Note that the pipe character must be
URL-escaped when it is sent in your API request. The URL-escaped value
for the pipe character is %7C.
So I use the tag "sketching" that I know is set in various videos. (A way to determine if a single video's tags is through https://www.googleapis.com/youtube/v3/videos?key=GOOGLE_KEY&fields=items(snippet(title,description,tags))&part=snippet&id=video_id )
https://www.googleapis.com/youtube/v3/search?q=%22sketching%22&part=snippet&channelId=CHANNEL_ID&maxResults=25&order=date&type=video&key=GOOGLE_KEY
That yields this:
{
"kind": "youtube#searchListResponse",
"etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/hPC7YXbOHVWNEk_6UiC5Jzdh5Zs\"",
"regionCode": "ES",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 25
},
"items": []
}
Nothing else. It says there are 10 results, but I don't see them, I do't know what they are. I tried sending the request without the "" but it returned the same result. Messing around I saw that when searching within a channel's videos from YouTube (as a browser client, through GUI, not API), it uses the parameter 'query'. So out of not having any more ideas I decided to substitute q for query.
https://www.googleapis.com/youtube/v3/search?query=sketching&part=snippet&channelId=UC4GRKWUEhUvsCqD-yNQpxQw&maxResults=25&order=date&type=video&key=GOOGLE_KEY
That query did yield results, but not of those videos who had that unique tag, but rather any video that had that tag or that word used in the title or description.
{
"kind": "youtube#searchListResponse",
"etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/xjWZRnm0X7B_csQX4KEu9nv_qdQ\"",
"regionCode": "ES",
"pageInfo": {
"totalResults": 24,
"resultsPerPage": 25
},
"items": [ ... ]
}
Any suggestions?

SonarQube 5.5 API - componentKey convention

I'm trying to extract coverage data from our SonarQube instance using the 'api/measures/component' endpoint. This is for a multi module java project. Using POSTMAN i can query for a single java file using a 'componentKey' which is build up of string like this
[maven-groupId]:[maven-artifactId]:[path to java file]
which generates a string like
com.i.pc.e.components.o:om-wf-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java
and returns this json response
{
"component": {
"id": "AVci_6G7elHqFlTqG_OC",
"key": "com.i.pc.e.components.o:om-wfl-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java",
"name": "Xxxx.java",
"qualifier": "FIL",
"path": "src/main/java/com/i/e/om/wf/actions/Xxxxx.java",
"language": "java",
"measures": []
},
"metrics": [
{
"key": "coverage",
"name": "Coverage",
"description": "Coverage by unit tests",
"domain": "Coverage",
"type": "PERCENT",
"higherValuesAreBetter": true,
"qualitative": true,
"hidden": false,
"custom": false,
"decimalScale": 1,
"bestValue": "100.0",
"worstValue": "0.0"
}
]
}
This is fine for a one-off request but I need to do this for a number of Java source files and I won't have the Maven details to hand.
Is there a convention or documentation on the format of the 'componentKey'?
Ideally i'd like to define the full package and java source file name in the 'compomentKey' or is there a way to look up the 'componentId' via some other REST API call?
Use the components service to iterate through your tree (or sub-trees within your tree) starting from your project and feeding your sonar.projectKey value into the baseComponentKey parameter. Pay particular attention to the strategy parameter, which determines what sub-set of children a call retrieves.
Once you have the data on each child, it should be simple to iterate through them to get their measures.

transfer a sibling element in a reponse to a parameter in Ready API / SOAP UI

I have one REST endpoint which returns a response like this
[
{
"id": "dbfff519-e8f6-4db3-9e26-a4e9014dc360",
"code": "123456789012345678901234567890123456789012345678901234567890",
"name": "client-code-with-character-length-sixty",
},
{
"id": "a673fb54-3503-4996-ba9b-a4e9014dc3ea",
"code": "18MTH",
"name": "18 Month",
},
{
"id": "60b781e3-4515-40f5-81ee-a4e9014dc400",
"code": "2periods",
"name": "I Have 2 Periods",
}...
etc.
I would like to be able to retrieve the ID where, for example, the code="2periods" UI can retrieve using either ResponseAsxml (with xpath) or Response with JSONPath. If I use the former I have managed to get the following to nearly retrieve my ID
//Response[1]/e[code='2periods']/id
BUT this looks like this
<id>0bc4aa5f-f8ab-4efe-b788-a4e9014dc45f</id>
And I don't know how to remove the start and end tags, the id has to be just the GUID.
I can't work out how to do something similar in the JSONPath - I've only managed to get something like
$[3].id
to work, but the order of the entities is not guaranteed in the test environment.
For ResponseAsXml using the XPath to get only the id value without <id> tag just add /text() to your actual expression:
//Response[1]/e[code='2periods']/id/text()
If you want to do the same using Response property with JSONPath try with:
$..[?(#.['code']=='2periods')].id[0]
Hope it helps,

convert JSON array to Ruby Hash (of hashes)

I'm trying to convert some API response data into a Ruby hash or array so I can more easily work with it. Here's the JSON string being returned by the API:
[
{
"id": 2,
"name": "TestThing",
"token": "B2CA27221DB976E48248F26756289B91"
},
{
"id": 3,
"name": "AnotherTestThing",
"token": "EF16E5F20B8463E48DBF3BA8F0E1102A"
}
]
I believe that is a JSON array? I tried doing JSON.parse on that string, but got (JSON::ParserError)r/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/json/common.rb:148:in 'parse': 746: unexpected token at '1511
What is the best way to convert this into something I can easily work with? My real goal here is to iterate over the tokens returned.
require 'json'
array = '[
{
"id": 2,
"name": "TestThing",
"token": "B2CA27221DB976E48248F26756289B91"
},
{
"id": 3,
"name": "AnotherTestThing",
"token": "EF16E5F20B8463E48DBF3BA8F0E1102A"
}
]'
JSON.parse(array)
My question did not show the full string I was trying to JSON.parse. I only put what I was trying to parse. I accidentally left some floating data before the JSON part of my string. Now that I have deleted that, it is working.

Resources