Matching multiple response in a single scenario outline - karate

I want to match multiple response of an API. Please find below Scenario Outline.
Background:
* def kittens = read('../sample.json')
Scenario Outline: Create Test1
Given url url
And request <Users>
When method POST
Then status 200
And match response.success.name == <expectedName>
And match response.success.contact.mobile == <expectedMobile>
Examples:
|Users|expectedName|expectedMobile|
|kittens.User1|'Micheal'|'123456'|
|kittens.User2|'Steve'|'998877'|
In the above case, I am able to match for 2 fields but I want to validate for more fields, but it is increasing pile of code that I do not want.
Multiple response of an API:
"success": {
"name": "Micheal",
"addr": "Tesla road",
"contact": {
"mobile": 123456,
"phone": 4422356
}
}
"success": {
"name": "Steve",
"addr": "Karen Road",
"contact": {
"mobile": 998877,
"phone": 244344
}
}
I am looking for minimizing the lines of code.
Can you please tell me another way where I can load entire response into expected and then I will traverse in the example section?
Please help me. Thank you !!

I strongly recommend you don't do this, and the reasons are explained in detail here: https://stackoverflow.com/a/54126724/143475
Also note instead of going field-by-field, you can use the whole JSON in the Examples column, or even pull from a file, see examples.feature.
You will actually end up with a much more "increasing pile of code" if you go down this path in my sincere opinion.

Related

Zabbix pre-processing item get item within an array with javascript

I don't have any experience with Javascript so I'm reaching out for the community to accomplish the below.
I have a few API calls configured on Zabbix which are working just fine. The thing is, not all of the results within an item is importante for me so I need to grab just what I want out of the array.
I'm using the pre-processing option on Zabbix to grab what I'm after but I can't get the code correct.
For instance, the below is one of the results Zabbix is getting.
[
{
"batteryLife": "15 minutes",
"communityString": "public",
"instanceId": "260596.1",
"instanceName": "UPS-01",
"ipAddress": "10.1.100.44",
"modelNumber": "GXT4-10000RT230",
"name": "UPS-01",
"objectType": "ScUps",
"scName": "pth-pf-04",
"scSerialNumber": 260596,
"serialNumber": "unknown",
"status": "Up",
"statusDescription": "Online",
"type": "Liebert"
}
]
How Can I Use the pre-processing to grab just the "ipAddress" value for instance?
Thanks for the help.
PeteF
You can avoid JavaScript preprocessing where you can use JSONPath preprocessing, see https://www.zabbix.com/documentation/current/manual/config/items/preprocessing/jsonpath_functionality
In your case:
$[0].ipAddress
A useful tool for JSONPath is http://jsonpath.com/
In case someone have the same doubt as I was having here is how I got it working to return the "ipAdress" value
var json = JSON.parse(value);
return json.ipAddress;
In case there are more than one dictionary inside of an array.
var json = JSON.parse(value);
return json[0].ipAddress;

How to SelectFrame dynamically in Salesforce?

I am trying to automate a script using Kantu in Salesforce.
Basically I am going through some dropdown IDs and select the right values and everything works IF the selectFrame value is correct in the beginning.
The problem is that Salesforce refreshes the iframe ID everytime the page is refreshed or a new case is opened (i.e. ext-comp-1018 | ext-comp-1035 | ext-comp-1048 etc.)
Because the script does not recognize the frame (since it is always changing), it won't go ahead to do the rest of the actions.
{
"Name": "SFDC_Auto",
"CreationDate": "2019-3-25",
"Commands": [
{
"Command": "selectFrame",
"Target": "id=ext-comp-1018",
"Value": ""
},
{
"Command": "select",
"Target": "id=cas5",
"Value": "label=Escalation"
},
I seen a post that mentioned this would be the solution, but I am not sure how to implement it in Kantu:
frames = #driver.find_elements(:xpath, '//iframe[starts-with(#id,ext-
comp-)]') #driver.switch_to.frame frames1
So far I could make this work: xpath=//iframe[starts-with(#id,ext-comp-)], however it doesn't do nothing. It reads ok but then halts at the next step saying that ID CAS5 is not recognized.
Can anyone help out?
Thanks,

Google Vision Text Detection returns too much unnecesary data

When using Google Vision to run text detection on a menu, the response from their API is way too large and returns way too much data that I don't need. I just want the text from the menu, not all the coordinates that come with the response. I can't find anything about narrowing down the response in any documentation i've read. Does someone know how to specify what fields get returned in the response?
Heres my request:
POST: https://vision.googleapis.com/v1/images:annotate?key=<MY_KEY>
BODY:
{
"requests": [
{
"image": {
"content": "...base64-encoded-image-content..."
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}
I figured it out. I could not find any documentation on how to do this, I had to just guess for like half an hour. If someone knows of any documentation on this let me know.
Anyway you can use the "fields" parameter to narrow down the response like so:
POST: https://vision.googleapis.com/v1/images:annotate?key=<MY_KEY>&fields=responses.fullTextAnnotation.text
This will only return the menu text from the Google Vision text detection API

I am facing issue for selenium webdriver script for Goibibo site city selection using xpath/css selector

While selecting city from site using xpath/css selector facing issue let me know solution
List<WebElement> frm=driver.findElements(By.cssSelector("html body div#gi_midcontent.col-md-12.col-sm-12.col-xs-12.pad0 div#gi_mid_in div#viewContainer div#flights-home-view.homeContainer.col-md-12.col-sm-12.col-xs-12.myPropDisplay div.homeContainerInner div#searchWidgetNew.blueBg.homeWidgetWrap.posRel form#gi_search div#searchWidgetCommon div.formWrap.padT15 div#source_st.fl_shAutosgBox.col-md-5.col-sm-5.col-xs-12.autoSuggestBox.marginB10 input#gi_source_st.form-control.inputTxtLarge.fromTxt.posRel"));
Couple of things.
Go through the selenium document here.http://www.seleniumhq.org/docs/03_webdriver.jsp
Read on how to use different locator strategy to identity particular locator.
Don't ask the question just because something is not working,spend some time on that.
Visit this page to understand how to ask question so that you can get answers.
The reason I have mentioned above point is you css locator looks pathetic, also the locator you are trying to identify has both name and id, and if you now how to use locator you could have figure that out.
The selector specified in the problem mixed id and class. However, taking a look at the website, the suggested city list is not offered as a group of input elements but fetched from AJAX.
Sending GET query with Postman tool on this URL and you can get JSON data with a list of objects. The property of json["data"]["r"][index]["xtr"]["cn"] seems a string of "CityName". This API does not require authentication so it can be fetched with Java HttpClient, too.
https://voyager.goibibo.com/api/v1/flights_search/find_node_by_name_v2/?search_query=hint&limit=10
The sample result:
{
"data": {
"r": [
{
"s_sc": 5055001,
"xtr": {
"cn": "Beica",
"cid": "1918715907401915921",
"cc": "ET",
"dis_type": "ldis",
"ar": 0,
"eid": "7717797727439208389",
"cnt_n": "Ethiopia",
"cnt_id": "1871100673297067773",
"dis": 0
},
"iata": "BEI",
"n": "Beica Airport",
"mt": "Beica Airport ### Beica",
"t": "airport",
"_id": "7717797727439208389",
"ct": {
"_id": "1918715907401915921",
"n": "Beica"
}
},
...
]
}
}
Please replace "hint" with your query string, for example, a letter to start with. Also take the note that (page) limit could not be greater than 50 in one query.

Does the JIRA REST API require submitting a transition ID when transitioning an issue?

If I POST an issue transition like this:
{
"fields" : {
"resolution" : {
"name" : "Fixed"
}
}
}
...I get this error:
{
"errorMessages" : ["Missing 'transition' identifier"],
"errors" : {}
}
This seems to imply that I need to include a transition ID along with my list of changed fields. https://stackoverflow.com/a/14642966/565869 seems to say the same. Fine.
However, transition IDs appear to be global. It's not enough to look up the highest transition ID for this issue and increment it; such an ID is probably in use elsewhere. At some expense, I could get the highest transaction ID used anywhere in the system; this might be 68,000 at this moment. But if I were then to use transaction ID 68,001 there's a real chance that a GUI user would attempt a transition of their own and use this ID before I could.
I could use transaction IDs in the range of 1,000,001 and up, but if the JIRA web GUI uses the highest previously used transaction ID when generating new IDs I'll just collide in this range instead of the 68,000 range. I could use 69,000 and trust that there won't be a thousand transitions in the length of time it takes to get the highest transaction ID.
These both seem terribly clumsy, however. Is there no way to post a transition and let JIRA generate its own unique ID? I don't need to retrieve the generated IDs, I just want to update issues' statuses and resolutions.
You're getting mixed up a bit. So lets see if I can explain it better for you.
To transition a JIRA Issue, you use the Transition ID to identify what transition to apply to the issue. You aren't specifying an ID for a transaction or a transition ID to identify that the transition occurred, JIRA takes care of this for you.
The easiest way to understand it is to see it.
So first you can look at what transitions are available to an Issue by doing a GET to the API Call:
/rest/api/2/issue/${issueIdOrKey}/transitions
Example:
/rest/api/2/issue/ABC-123/transitions
Which will show something like this:
{
"expand": "transitions",
"transitions": [
{
"id": "161",
"name": "Resolve",
"to": {
"description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
"iconUrl": "https://localhost:8080/images/icons/statuses/resolved.png",
"id": "5",
"name": "Resolved",
"self": "https://localhost:8080/rest/api/2/status/5"
}
}
]
}
So you can see only 1 transition is available for issue ABC-123 and it has an ID of 161.
If you were to browse to that JIRA Issue through the GUI, you would see only 1 Transition available and it would match the API Call. In fact if you inspected the element you should see it having an a tag and in the href something like action=161
So should you want to transition this issue, you'll need to do a POST to the following URL:
/rest/api/2/issue/ABC-123/transitions
With JSON like this:
{
"update": {
"comment": [
{
"add": {
"body": "Bug has been fixed."
}
}
]
},
"fields": {
"assignee": {
"name": "bob"
},
"resolution": {
"name": "Fixed"
}
},
"transition": {
"id": "161"
}
}
Which uses the transition ID found from the call that shows all transitions. I also update the resolution and assignee and add comments at the same time.
That make a bit more sense?