How to use data in a file with postman? - api

I have a list of IDs and Values in a file and would like to use postman to connect to an API and update the records found in this file.
I tried with the Runner but am stuck in writing the syntax.

The answer is pretty simple and very well explained on this page
You can start with the a basic "put/post" - try to modify one single data set with static values to determine how the final query needs to be build. In my case the API accepted only RAW JSON formated data payloads.
As soon as you have your static postman query running - you can start automating it by determining which parts should be replaced. This data should be found in a data file (JSON or CSV). The schema is important for postman to understand the data. As reference I state the example as if I would like to replace an ID and a Value. My data document has one more column which is not a problem.
+--------+--------+--------+
| id | email | value |
+--------+--------+--------+
| data 1 | data 1 | data 1 |
+--------+--------+--------+
| data 2 | data 2 | data 2 |
+--------+--------+--------+
| data 3 | data 3 | data 3 |
+--------+--------+--------+
Column two (aka email) will be ignored and not be used. Notice how "id" and "value" are written in the header.
I would like to replace the ID which needs to be attached to the API endpoint and like to update a value which is within the dataset of this ID. Replacing the static parts with variables like {{variable}} allows Postman to understand that it needs to fill dynamic data here.
Notice that the variable attached to the URL says that it is not defined in the environment - if you did not set it up in the environment, this is correct and will work with data files.
I used simple tests to confirm if the data of the file made it into my query:
tests["URL has ID"] = responseURL.has(data.id);
tests["Body contains SFID"] = responseBody.has(data.value);
If you reach this point - all there is left to do is to go to the runner page, select the query to run, add the data file (you should preview if everything looks okay) and run it.

Related

Set data from data when reading XML with karate

I'm reading an xml file to build it dynamically using a table.
Scenario: Create subscriber base
* table data
|PaidMode|BillCycleCredit|BillCycleType|PrimaryOffer|SubscriberNo |
|'0' |'100000' |'1' |'500033' |'#(postPaidSubscriber1)'|
|'0' |'100001' |'1' |'500035' |'#(postPaidSubscriber2)'|
* def Request = read('newSubscriber.xml')
And request Request
* print Request
My xml file (exert):
<NewSubscriberRequest>
<new1:Customer>
<shar:FirstName>#(FirstName)</shar:FirstName>
<shar:LastName>#(LastName)</shar:LastName>
<shar:LangType>#(LangType)</shar:LangType>
</new1:Customer>
<new1:Account>
<shar:PaidMode>#(PaidMode)</shar:PaidMode>
<shar:BillCycleCredit>#(BillCycleCredit)</shar:BillCycleCredit>
<shar:CreditCtrlMode>#(CreditCtrlMode)</shar:CreditCtrlMode>
<new1:BillCycleType>#(BillCycleType)</new1:BillCycleType>
</new1:Account>
I've had a look at this solution, How to use dynamic values for Karate Features, he seams to want to do the same thing but it doesnt work for me i get the below error.
feature call loop failed at index: 0, match failed: EQUALS
$ | not equal | match failed for name: 'SubscriberNo' (MAP:MAP)
{"PaidMode":"0","BillCycleCredit":"100000","BillCycleType":"1","PrimaryOffer":"500033","SubscriberNo":"#(postPaidSubscriber1)"}
{"PaidMode":"0","BillCycleCredit":"100000","BillCycleType":"1","PrimaryOffer":"500033","SubscriberNo":"#(postPaidSubscriber1)"}
$.SubscriberNo | not equal (STRING:STRING)
'#(postPaidSubscriber1)'
'699111115'
I'm now here https://github.com/karatelabs/karate/blob/v1.2.0/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature again trying to figure out how best to do this. This question is similar to my previous question How to set a variable in the xml per scenario just want to read it from a table to create my subscriber base basically for readability and usage reasons. Sorry Peter I see you get alot of these type of questions (second from me alone lol). I just need a little nudge I think
I really think you don't need to do this in a table: '#(postPaidSubscriber1)' - just use the variable name as-is. Refer the docs: https://github.com/karatelabs/karate#table
* table data
|PaidMode|BillCycleCredit|BillCycleType|PrimaryOffer|SubscriberNo |
|0 |100000 |1 |500033 |postPaidSubscriber1|
|0 |100001 |1 |500035 |postPaidSubscriber2|

How can I put several extracted values from a Json in an array in Kusto?

I'm trying to write a query that returns the vulnerabilities found by "Built-in Qualys vulnerability assessment" in log analytics.
It was all going smoothly I was getting the values from the properties Json and turning then into separated strings but I found out that some of the terms posses more than one value, and I need to get all of them in a single cell.
My query is like this right now
securityresources | where type =~ "microsoft.security/assessments/subassessments"
| extend assessmentKey=extract(#"(?i)providers/Microsoft.Security/assessments/([^/]*)", 1, id), IdAzure=tostring(properties.id)
| extend IdRecurso = tostring(properties.resourceDetails.id)
| extend NomeVulnerabilidade=tostring(properties.displayName),
Correcao=tostring(properties.remediation),
Categoria=tostring(properties.category),
Impacto=tostring(properties.impact),
Ameaca=tostring(properties.additionalData.threat),
severidade=tostring(properties.status.severity),
status=tostring(properties.status.code),
Referencia=tostring(properties.additionalData.vendorReferences[0].link),
CVE=tostring(properties.additionalData.cve[0].link)
| where assessmentKey == "1195afff-c881-495e-9bc5-1486211ae03f"
| where status == "Unhealthy"
| project IdRecurso, IdAzure, NomeVulnerabilidade, severidade, Categoria, CVE, Referencia, status, Impacto, Ameaca, Correcao
Ignore the awkward names of the columns, for they are in Portuguese.
As you can see in the "Referencia" and "CVE" columns, I'm able to extract the values from a specific index of the array, but I want all links of the whole array
Without sample input and expected output it's hard to understand what you need, so trying to guess here...
I think that summarize make_list(...) by ... will help you (see this to learn how to use make_list)
If this is not what you're looking for, please delete the question, and post a new one with minimal sample input (using datatable operator), and expected output, and we'll gladly help.

Karate- Good way to send custom headers with each request

I have a scenario where I am doing a GET call and on my table I have parameters defined. Now for the headers, I want to purposefully send incorrect values to make sure the test fails as expected. Not really sure how to do it though.
I have the following setup:
* table input
| machine | version | osSystem | status |
| machineName| version | windows | 401 |
My secondary file that the above calls on, looks like this:
Given url env
And path path
And header Content-Type = 'application/xml; charset=UTF-16'
And header Accept = '*/xml; charset=UTF-16'
And header key = key
When method GET
In above, I want to send bogus values for "key" header. Total of six bogus values (random alpha string, random number string, random alphanumerical value, random guid, etc). I have obviously tried entering the values as a json under "and header key = {}" but how do I make each request run EACH header per request, instead of running them all in one request?
Thank you in advance!
Try this example and observe how it works, it will answer all your questions:
Scenario Outline:
* url 'https://httpbin.org/anything'
* header foo = header
* method get
Examples:
| header |
| one |
| two |
And for an alternate way to "loop" refer to this answer: https://stackoverflow.com/a/69422451/143475

Writing Cucumber feature file with passing unique data every time test runs

I want to write a feature file that will pass unique data everytime I run my test.
Feature : - Create Facebook account
Scenario Outline: Create new account
Given I go to facebook.com
And I enter "First_Name>Last_name>DOB>Password>ConfirmPassword>Email>ConfirmEmail>"
When I click on Create account
Then I should get welcome to facebook message
Examples:
| First_Name | Last_name | DOB | Password | ConfirmPassword | Email | ConfirmEmail |
| Gary | English | 11/01/1989 | test123 | test123 | gar#mail.com | gar#mail.com |
| Barry | Smith | 01/11/1982 | test123 | test123 | bar#mail.com | bar#mail.com |
My question is:
When I run above scenario there will be 2 Facebook accounts created. When I commit my code and test are run every morning, they will fail unless I change email every-time to make them unique. As any system will check if email address provided already exists or not.
How do I tackle this issue where I don't have to change my Create account feature file data every time.
I hope someone of us should have come across such issue.
Note: I could not open and close <> as text was not visible between those brackets, hence I have kept just 1 bracket
Then don't put it in the feature file. Build a randomizer into the steps method. You should also change the feature file to reflect this.
And I enter "<First_Name>, <Last_name>, <DOB>, <Password>, <ConfirmPassword>, <Email>, <ConfirmEmail>"
And uses a random email
Or if you'd rather not build a separate condition, then use a keyword to signal that the value should be randomized (my preferred method):
|Barry|Smith|01/11/1982|test123|test123|[random]|[random]|
So when passed to the registration method, if the value doesn't validate as a legitimate email address (you are doing validation, right?), check for the [random] keyword. If it is there, then build a random valid email.

QTP Unable to differentiate Web Table in Application

I am a beginner in QTP and I am working on an application where there are two different web tables displayed.
The second web table is detail description of the first web table so it displays when we select a row in the first web table.
In other words, Each row in the first table is selectable and when selected corresponds to the second web table
Web table 1 contains something like below for a user
RelationShip | Name
Father | AAA
Mother | BBB
Brother | CCC
Sister | DDD
Sister2 | EEE
Web Table 2 Contains detailed information for each row in Web Table 1 as I earlier mentioned. SO for Father, the below table is reflected
Details
Name | AAA
Age | 50
Relationship | Father
and so on
Second User might/might not have brother/sister.
The problem now I am facing is retrieving data from second web table for different entity of first one since all the property of the web table are similar expect the below property
"html ID" which corresponds to - "DetailParty_randomno"
This random number is the one which defines the uniqueness of the second web table, which can be retrieved from the first web table though it isn't found in the properties section when we use the Object spy.
I can see this random number when I view the source code of the page. It's displayed as value entity in the tr tag
Value entity looks like "Party_randomno"
<tr style="background-color:yellow" value="Party_1" onclick="Call peoplehighlight("Party_1")" language="vbscript">
My question is if there a way to retrieve this value for each row and then use it in identifying the second web table?
However I did try to read from second table by hard coding "html id" in webtable property to see if it's being read but it didn't work
So my second question is with respect to the correctness of the below descriptive programming code. Is there something else I need to include/exclude in the WebTable property to find uniqueness.
I also did my research and found that it's useful to use index but I am not aware on how to find the index of a web table? Also the index changes for each user I am searching and hence I need to find the index of the table during run time before using it
BrowserName = Browser("micClass:=Browser").GetROProperty("name")
PageName= Browser("micClass:=Browser").Page("micClass:=Page")GetROProperty("name")
Set desc = Description.Create()
desc("html tag").Value = "tr"
Set Rows = Browser("B").Page("P").Webtable("WT").ChildObjects(desc)
RoCounter = Rows.Count-1
For valuecount = 0 To RoCounter
id= rows(i).Object.GetAttribute("value")
Next
'When the right ID is got, parsing it in the below for WT2 Identification
Set ObjTable = Browser("name:="&Browsername).Page("name:="& Pagename).WebTable("class:=Web_Table", "html id:=Detail"&id)
Update
I was able to get the value from the source code using Motti's code. needed to tweak a little and my descriptive programming had spaces between name and : so the objetct wasn't being recognized. It's solved now.
When looking at the description you gave to your WebTable I find it hard to see what you're trying to achieve. class in QTP is mapped to the html className property are you sure that Web_Table is correct className? Also there is (AFAIK) no class name property in QTP, if you mean the test object type then there's no need to add it since you already said that the object is a WebTable.
To answer your question, in order to add indexing you just add "index:=1" to the smart identification (or in the description if you're using the object repository), note that index is zero based so 1 is the second object that matches the description (if there are more than one, if there is only one the index is ignored).
In order to get the random number you can try something like this (untested)
Set desc = Description.Create()
desc("html tag").Value = "tr"
Set rows = Browser("B").Page("P").WebTable("T").ChildObjects(desc)
For i = 0 To rows.Count - 1
id = rows(i).GetROProperty("value") ' Or whatever you need here
Next