QAF | In Data driven testing, retrieving csv data row directly inside StepDef - bdd

In my setup using QAF Gerkin, I have an 80+ data column in the test data file which is very difficult to pass all the columns in steps using "<data_column>". I would like to retrieve all the column data directly in my StepDef according to data-driven iteration. I have tried using getBundle().getString("column_name"), but it is not working.
Eg:
Feature File:
Scenario outline: UI-34_Customer Creation
And I request api "get.sample.call"
And I assert api response status is "200"
And Test Data Retrive
Examples: {"datafile": "data/scenarios/1622630669181.csv", "filter": '(_status==true) && (_id.equalsIgnoreCase("UI-34"))'}
StepDef:
QAFTestStep(description="Test Data Retrive")/**/
public void testDataRetrive(){
System.out.println("============>>>>>>>==========");
System.out.println(getBundle().getString("customer_name"));
System.out.println("============<<<<<<<>>>>>>>==========");
}
Note: I'm able to retrive the data, if I mention the column name directly in Step.

Your step need to accept argument and value need to passed when called. In order to pass record/entry from data-provider you can use args[0] reference as value.
Refer example below:
#QAFTestStep(description="Test Data Retrive {testdata}")
public void testDataRetrive(Map<String, Object> data){
System.out.println("============>>>>>>>==========");
System.out.println(data.get("customer_name"));
System.out.println("============<<<<<<<>>>>>>>==========");
}
Scenario outline: UI-34_Customer Creation
And I request api "get.sample.call"
And I assert api response status is "200"
And Test Data Retrive "${args[0]}"
Examples: {"datafile": "data/scenarios/1622630669181.csv", "filter": '(_status==true) && (_id.equalsIgnoreCase("UI-34"))'}
Refer answer to similar question.

Related

Zoho creator ,Invalid JSON payload received, when trying to integrate creator-form-data to google sheet

Objective: I am trying to integrate creator-form-data with google-sheet using google-sheet-api-v4.
I am able to create an empty sheet(data params being empty ) at google spreadsheets.
but i don't know ,how to create sheet with data-params , to either-
(1) assign title ,to spreadsheet , or
(2) write any data, to spreadsheet
error received : using deluge to perform task no. ( 1 ), the error thrown is :
Invalid JSON payload received. Unexpected token
Note:
(1)Oauth credentials are checked and correct,
google access token is also valid, confirming via
Google-oauth-playground
(2) i am able to assign title and data from google-try-api-platform,but no success from deluge side.
google-sheet-try-api
The issue is solved now ,in postUrl the post-data to be posted , must be converted from json to string (params=data.toString(); ).
I had sent post-data in json format thats the mistake I made.
Below is correct sample code for deluge:
append_data = {"values":{{thisDate,thisQuantity}}};
final_append_data = append_data.toString();
response = postUrl(append_data_sheet_url,final_append_data,mymap,false);
Note: variable "final_append_data" is converted to string.

matchesJsonSchemaInClasspath in not working even if the input and output is fairly different

I have been trying to use the matchesJsonSchemaInClasspath method for verifying my API against a predefined JSON, but even if I JSON format, the test case keeps on getting passed, not sure what am I doing wrong here. Or is it the limitation for this.
This is my piece of code.
#Test
public void test(){
given().get("http://jsonplaceholder.typicode.com/posts/1").then()
.assertThat().body(matchesJsonSchemaInClasspath("postpaidAccCard.json"))
.log().all();
}
and the static data I have in "postpaidAccCard.json" is :-
{
"time": "03:53:25 AM",
"milliseconds_since_epoch": 1362196405309,
"date": "03-02-2013"
}
Still the test is passed, will be great if someone can help me out with this.
matchesJsonSchemaInClasspath is a method that compares JSON schema (not plain JSON) with the provided API response (JSON).
For creating JSON schema of an API response:
Go to https://jsonschema.net/home
Paste the API response in the left side window and click on Submit button.
Your JSON schema file will be displayed on the right side window.
Copy and paste the JSON schema in the postpaidAccCard.json file and rerun your test.

OData : Why am I getting HTTP 428 (Precondition Required) error while performing an update

So here's my code
sap.ui.getCore().getModel("myModel").update("/ZSystemNameSet(mandt='001')", data, null, function(datay, responsey){
sap.ui.getCore().getModel().refresh();
MessageToast.show("It worked...!! Data: "+datay+"Response: "+responsey);
}, function(datax,responsex){
MessageToast.show("Sorry! Data: "+datax+"Response: "+responsex);
});
Also how do I add the header attributes to the update() call?
Obviously your service uses optimistic locking and expects an If-Match header, containing the ETag of the entity, in the request. You can pass this ETag as parameter to the update method. For further details you should check your service definition and the documentation.
Regarding the update of header attributes: It is hard do answer as there is no information regarding your entity orchestration. Normally you should be able to add a property containing the update information for you header to the data structure you send to the server, e.g. if the header is reachable from your entity ZSystemName via association "Header" you do the following:
data.Header = { "attribute1" : value1, "attribute2" : value2 }

Jersey POST operation with PathParam and JSON Object

By design, GET operation should be used only for read Only operation. Howeevre,i am looking for a plausible way of implementaion of following.Implement a POST operation that can be called as it is mentioned below
POST /my-store/order/D : where D is the day the customer place an order
Request: POST /my-store/order/14
{
"customer" : "XYZ",
"order" : {
"item1" : 2
}
}
I tried implementing using below function
#Path("/D")
#POST
#Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
#Produces({ MediaType.APPLICATION_JSON })
public Response submitOrder(#PathParam("D") int elapsedDays, #Context UriInfo uriInfo, Order orderInfo){
..........
}
But the above implementation does not seem to working. When I try to test the implementation using MyEclipse REST explorer ,it does not offer option to pass in Order object but allow 'D' parameter only. However, if #PathParam and #Path is removed then it works perfectly fine i.e. allows to consume JSON Order object.
But,the requirement is to pass the days as Path parameter and Order object as JSON input in POST request.
Looking for suggestion on implementation approach and design approach.
Thanks in advance
For one thing, your path should be configured like this:
#Path("/{D}")
I assume your extended ellipses means you have some method parameter that represents the deserialization of your order.

WebAPI: Upload picture & get byte array

I want the user to be able to upload a file via my application. I don't have DB access, all my data calls get completed via a web-service that another person is writing. I needed to secure the web service, so I've consumed it & exposed it via WebAPI, & added OAuth security.
Now to my problem.
I've written the following.
public Task<FileResult> Post()
{
if (Request.Content.IsMimeMultipartContent())
{
var task = Request.Content.ReadAsByteArrayAsync().ContinueWith(
o =>
{
var result = this.Client.UploadPicture(this.UserId, o.Result);
if (result.ResultCode == 0)
{
return new FileResult()
{
Message = "Success",
FileId = result.ServerId
};
}
throw new HttpResponseException(...);
});
return task;
}
...
}
I'm pretty much a noob when it comes to WebAPI & multithreading (I'm not sure why this needs to be handled async? I'm sure there is a reason, but for now I'd just like a working example and get to the why later..).
My code is loosely based on some R&D & samples I've found on the net, but i haven't come across a scenario like I'm needing to complete... Yet it doesn't seem like I'm doing something out of the ordinary...
Upload a file to the server, and pass the image byte[] object to either sql or another service?
In this line
var result = this.Client.UploadPicture(this.UserId, o.Result);
I'm uploading a byte[] array of something....
Then later (the retrieval method works, I've managed to retrieve & view a test image)
When retrieving the byte array of the "image" i uploaded i get an array of idk what.. EG, i get a valid result of something, but it ain't no picture. Which leads me to believe that the uploaded data is bogus :|
O_o
How to get the image byte[]?
Mime Multipart is more than just your array of bytes. It also has metadata and boundary stuff. You need to treat it as MultiPartContent and then extract the image byte array out of that.
Filip has a blog post on the subject here.

Resources