Re: JSON data in Web_custom_request- Vugen

1,500 views
Skip to first unread message

kantharaja t

unread,
Jan 28, 2013, 8:15:37 PM1/28/13
to LR-Loa...@googlegroups.com
Covert JSON to XML and use webservice protocol.

On Mon, Jan 28, 2013 at 4:35 PM, Nav <naveen....@gmail.com> wrote:
Hello All

I need to test REST services through Loadrunner  and i am currently in scripting phase.

How do i send the JSON payload in web_custom_request?

I already have headers added and formatted the JSON string.

Here is the string that i captured from request through fiddler logs.

{"Id":21,"IsDisplayed":true,"Sequence":21,"Content":{"Name":"Test0b324f6fbe4f41b5bad9f3d0215f0afe","Description":"stuff04e785477fd04706b333eae8a62e86f7","PageTitle":"testpage","LocaleCode":"en-US","MetaTagTitle":"title","MetaTagDescription":"stuff","MetaTagKeywords":"test","Slug":""},"AuditInfo":{"UpdateDate":null,"CreateDate":null,"UpdateBy":null,"CreateBy":null}}


formatted string is:
 "{\"Id\":21,\"IsDisplayed\":true,\"Sequence\":21,\"Content\":{\"Name\":\"Test0b324f6fbe4f41b5bad9f3d0215f0afe\",\"Description\":\"stuff04e785477fd04706b333eae8a62e86f7\",\"PageTitle\":\"testpage\",\"LocaleCode\":\"en-US\",\"MetaTagTitle\":\"title\",\"MetaTagDescription\":\"stuff\",\"MetaTagKeywords\":\"test\",\"Slug\":\"\"},\"AuditInfo\":{\"UpdateDate\":null,\"CreateDate\":null,\"UpdateBy\":null,\"CreateBy\":null}";

Also if i need to create a parameter for the Name and Description, how do i create?

Any suggestions?




--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group, send email to LR-LoadRunne...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks and Regards
 Kantharaja

Laxman

unread,
Jan 29, 2013, 12:48:50 AM1/29/13
to LR-Loa...@googlegroups.com
Send the entire value in body and it will work

Sent from my iPhone

Franklin Inbaraj

unread,
Jan 29, 2013, 9:58:55 AM1/29/13
to LR-Loa...@googlegroups.com
Json and LR use {} braces to pass parameter values.

Build Json request same like XML request using web_custom_request function. In LR, change the setting to use some other braces like <>,[] etc to pass the parameter values.

-Franklin Inbaraj

On Tue, Jan 29, 2013 at 2:44 AM, HarryGG <har...@gmail.com> wrote:
Use the Json 2 XML data format extension, then use the Snapshots xml browser to review and correlate. It's a great feature, developed exactly for such purposes.

Regards,
Harry

On Monday, January 28, 2013 11:35:44 PM UTC+2, Nav wrote:
Hello All

I need to test REST services through Loadrunner  and i am currently in scripting phase.

How do i send the JSON payload in web_custom_request?

I already have headers added and formatted the JSON string.

Here is the string that i captured from request through fiddler logs.

{"Id":21,"IsDisplayed":true,"Sequence":21,"Content":{"Name":"Test0b324f6fbe4f41b5bad9f3d0215f0afe","Description":"stuff04e785477fd04706b333eae8a62e86f7","PageTitle":"testpage","LocaleCode":"en-US","MetaTagTitle":"title","MetaTagDescription":"stuff","MetaTagKeywords":"test","Slug":""},"AuditInfo":{"UpdateDate":null,"CreateDate":null,"UpdateBy":null,"CreateBy":null}}


formatted string is:
 "{\"Id\":21,\"IsDisplayed\":true,\"Sequence\":21,\"Content\":{\"Name\":\"Test0b324f6fbe4f41b5bad9f3d0215f0afe\",\"Description\":\"stuff04e785477fd04706b333eae8a62e86f7\",\"PageTitle\":\"testpage\",\"LocaleCode\":\"en-US\",\"MetaTagTitle\":\"title\",\"MetaTagDescription\":\"stuff\",\"MetaTagKeywords\":\"test\",\"Slug\":\"\"},\"AuditInfo\":{\"UpdateDate\":null,\"CreateDate\":null,\"UpdateBy\":null,\"CreateBy\":null}";

Also if i need to create a parameter for the Name and Description, how do i create?

Any suggestions?




--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to LR-LoadRunne...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Regards,
Franklin Inbaraj

Franklin Inbaraj

unread,
Jan 29, 2013, 3:34:56 PM1/29/13
to LR-Loa...@googlegroups.com
i see [] brackets in json body... give a try with <> braces to pass parameter values...

On Tue, Jan 29, 2013 at 1:46 PM, Nav <naveen....@gmail.com> wrote:
I changed the parameter string to []   but still i see the following warnings int he script, through the script gets successfully executed.
 
Here is the script
 
Any suggestions?
 
 
------------------------------
    char *request_json_base;
    char *request_json;

      web_add_header("Content-Type", "application/json; charset=utf-8");
    web_add_auto_header("x-vol-site","2238");
    web_add_auto_header("x-vol-tenant","21238");
    web_add_auto_header("x-vol-locale","en-US");
    web_add_auto_header("x-vol-currency","USD");

   
   request_json_base=  "{\"Email\":\"{EmailID}\",\"OrderStatus\":\"New\",\"PaymentStatus\":\"AwaitingPayment\",\"FulfillmentStatus\":\"NotFulfilled\",\"Items\":[{\"Id\":\"4031e206-edc9-42d6-9a5c-230e05f0273b\",\"Product\":{\"Name\":\"Test Product\",\"Description\":\"Test Product description\",\"ProductCode\":\"tepee21f81a\",\"Categories\":[{\"Id\":2184}],\"Price\":{\"Price\":0.0000},\"IsTaxable\":true},\"Quantity\":2,\"SubTotal\":1000.0,\"Total\":1000.0}]}";
   request_json = lr_eval_string(request_json_base);
   lr_save_string(request_json, "REQUEST_JSON_PARAM");
    
   lr_start_transaction("next.Order_CreateOrder");
     web_custom_request("CreateOrder",
    "URL=http<Hostname>/next.Order.WebApi/orders",
    "Method=POST",
    "TargetFrame=",
    "Resource=0",
    "Referer=",
    "Mode=HTTP",
    "RecContentType=text/html",
    "EncType=application/json",
    "Body={REQUEST_JSON_PARAM}",
    LAST); 
 lr_end_transaction("next.Order_CreateOrder", LR_AUTO);
    
 
RESPONSE:
Notify: max connections per server : 2
Starting action Action.
Action.c(7): web_add_header("Content-Type") started   [MsgId: MMSG-26355]
Action.c(7): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway   [MsgId: MWAR-26593]
Action.c(7): web_add_header("Content-Type") highest severity level was "warning"   [MsgId: MMSG-26391]
Action.c(8): web_add_auto_header("x-vol-site") started   [MsgId: MMSG-26355]
Action.c(8): web_add_auto_header("x-vol-site") was successful   [MsgId: MMSG-26392]
Action.c(9): web_add_auto_header("x-vol-tenant") started   [MsgId: MMSG-26355]
Action.c(9): web_add_auto_header("x-vol-tenant") was successful   [MsgId: MMSG-26392]
Action.c(10): web_add_auto_header("x-vol-locale") started   [MsgId: MMSG-26355]
Action.c(10): web_add_auto_header("x-vol-locale") was successful   [MsgId: MMSG-26392]
Action.c(11): web_add_auto_header("x-vol-currency") started   [MsgId: MMSG-26355]
Action.c(11): web_add_auto_header("x-vol-currency") was successful   [MsgId: MMSG-26392]
Action.c(15): Notify: Parameter Substitution: parameter "EmailID" =  "test...@testuser.com"
Action.c(15): Warning: The string '"Id":2184' with parameter delimiters is not a parameter.
Action.c(15): Warning: The string '"Price":0.0000' with parameter delimiters is not a parameter.

Action.c(16): Notify: Saving Parameter "REQUEST_JSON_PARAM = {"Email":"test...@testuser.com","OrderStatus":"New","PaymentStatus":"AwaitingPayment","FulfillmentStatus":"NotFulfilled","Items":[{"Id":"4031e206-edc9-42d6-9a5c-230e05f0273b","Product":{"Name":"Test Product","Description":"Test Product description","ProductCode":"tepee21f81a","Categories":[{"Id":2184}],"Price":{"Price":0.0000},"IsTaxable":true},"Quantity":2,"SubTotal":1000.0,"Total":1000.0}]}".
Action.c(18): Notify: Transaction "next.Order_CreateOrder" started.
Action.c(19): web_custom_request("CreateOrder") started   [MsgId: MMSG-26355]
Action.c(19): Notify: Parameter Substitution: parameter "REQUEST_JSON_PARAM" =  "{"Email":"test...@testuser.com","OrderStatus":"New","PaymentStatus":"AwaitingPayment","FulfillmentStatus":"NotFulfilled","Items":[{"Id":"4031e206-edc9-42d6-9a5c-230e05f0273b","Product":{"Name":"Test Product","Description":"Test Product description","ProductCode":"tepee21f81a","Categories":[{"Id":2184}],"Price":{"Price":0.0000},"IsTaxable":true},"Quantity":2,"SubTotal":1000.0,"Total":1000.0}]}"
Action.c(19): t=5119ms: 294-byte response headers for "http://<Hostname>/next.Order.WebApi/orders" (RelFrameId=1, Internal ID=1)
Action.c(19):     HTTP/1.1 201 Created\r\n



--
Regards,
Franklin Inbaraj

Franklin Inbaraj

unread,
Jan 29, 2013, 3:37:59 PM1/29/13
to LR-Loa...@googlegroups.com
tools -> general options -> parameterization and define the left and right braces
--
Regards,
Franklin Inbaraj

Reply all
Reply to author
Forward
0 new messages