The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> OpenSTA

Pages: 1
pawanr
Member


Reged: 10/03/11
Posts: 87
json key in client side java script
      #706463 - 05/09/12 10:46 AM

We have application developed on Java. It contains json key wrote in java script and has jQuery and execute at client side. Does opensta able to extract json key??

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #706656 - 05/11/12 06:29 AM

Yes, it can. If it is in the first 64KB of the response from the the system under test.

Read more here http://www.sqaforums.com/showflat.php?Cat=0&Number=550390&Main=526420

Its not related to the json key, but it will show you an alternate way to extract data from a response. Use the LOAD RESPONSE INFO BODY and LOG commands to print the response from the system under test. Figure out what delimits the json key and use the subroutine in the example to extract the json key.

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: Bernie Velivis]
      #706811 - 05/14/12 12:33 AM Attachment (177 downloads)

Thanks bernie, after using LOAD RESPONSE INFO BODY and LOG command it gives error in my script. I want to correlate JSON_KEY=50256881453058889668080303786771909748660895760& but can't understand how to do because DOM structure is not visible for json. Can you please provide me some code to extract json key. For your reference please find attached script.

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #706853 - 05/14/12 03:41 AM


Load ALL off the response into a variable and log it.

Change


LOAD RESPONSE_INFO BODY ON 1 &
INTO logged &
,WITH "HTML(0)/HEAD(0)/TITLE(1):TEXT:(0)"
log logged


to

LOAD RESPONSE_INFO BODY ON 1 &
INTO logged
log logged


Look for your json id in the text that is logged.

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: Bernie Velivis]
      #706974 - 05/15/12 04:22 AM Attachment (853 downloads)

I am able to extract the page now but on json request i get error "error has occurred" because json_key need to be correlate. How can i replace json key with variable so that script can successfully execute. For your reference please find attached replay log file.

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script *DELETED* [Re: pawanr]
      #706978 - 05/15/12 04:47 AM

Post deleted by pawanr

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: pawanr]
      #706979 - 05/15/12 04:48 AM Attachment (147 downloads)

After correlating script i get below error still not able to extact JSON_KEY also please find attached herewith correlated script.

cmfrwk-webmvc/shiptopartylist.json?JSON_KEY=&564431776=14-20-1337076435987&_search=false&nd=1337076501393&rows=-1&page=1&sidx=&sord=asc HTTP/1.1
TModeller_Web.exe|1524|1-1|PLACE_ORDER_15_MAY|673|E* HTTPRESPONSE: No data available for connection id(1)
TModeller_Web.exe|1524|1-1|PLACE_ORDER_15_MAY|673|E* TScript::run: ERROR in TOF execution; resuming...
TModeller_Web.exe|1524|1-1|PLACE_ORDER_15_MAY|676|E* HTTPRESPONSE: No data available for connection id(1)
TModeller_Web.exe|1524|1-1|PLACE_ORDER_15_MAY|676|E* TScript::run: ERROR in TOF execution; resuming...
1-1 :[677]:SET VARIABLE UDLV_OFFSET: 0
1-1 :[678]:SET VARIABLE UDLV_TEMP:
1-1 :[679]:SET VARIABLE UDLV_OFFSET: 12
TModeller_Web.exe|1524|1-1|PLACE_ORDER_15_MAY|680|E* ERROR: FAILED PROCESSING TOF RECORD FOR SCRIPT LINE 680
!Script Execution Failed.

Edited by pawanr (05/15/12 04:56 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #707005 - 05/15/12 08:23 AM

You need to correlate jsessionid.

Read this http://www.iperformax.com/downloads/osta_correlation.pdf

You load load the session id here


PRIMARY GET URI "http://ambujawstest:8080/ HTTP/1.1" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Host: ambujawstest:8080", &
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", &
"Accept-Language: en-us,en;q=0.5", &
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", &
"Connection: keep-alive"}

Load Response_Info Header on 2 &
Into cookie_2_0 &
,WITH "Set-Cookie,JSESSIONID"

but you dont use it here

PRIMARY GET URI &
"http://ambujawstest:8080/cmfrwk-webmvc/intro.do;jsessionid=434F9D386D7F437E993234E42810209C " &
"HTTP/1.1" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Host: ambujawstest:8080", &
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", &
"Accept-Language: en-us,en;q=0.5", &
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", &
"Connection: keep-alive", &
"Cookie: "+cookie_2_0}


edit the script and globally substitute

434F9D386D7F437E993234E42810209C

with

"+cookie_2_0+"

so it looks like this

PRIMARY GET URI &
"http://ambujawstest:8080/cmfrwk-webmvc/intro.do;jsessionid="+cookie_2_0 +" " &
"HTTP/1.1" ON 2 &
HEADER DEFAULT_HEADERS &
,WITH {"Host: ambujawstest:8080", &
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", &
"Accept-Language: en-us,en;q=0.5", &
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", &
"Connection: keep-alive", &
"Cookie: "+cookie_2_0}

Edited by Bernie Velivis (05/15/12 06:15 PM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: Bernie Velivis]
      #707087 - 05/16/12 01:02 AM Attachment (242 downloads)

Thanks Bernie, jsessionid also pass now but still not able to extract json key it shows error "key not available".

Please find attached correlated script and below mentioned replay logs.

cmfrwk-webmvc/shiptopartylist.json?JSON_KEY=&1323348930=22-17-1337147044027&_search=false&nd=1337147084258&rows=-1&page=1&sidx=&sord=asc HTTP/1.1
1-1 :[710]:Connection 8: receiving results with status 200
1-1 :[710]:Connection 4: receiving results with status 200
1-1 :[710]:Connection 2: receiving results with status 200
1-1 :[710]:Connection 3: receiving results with status 200
1-1 :[710]:HTTPRESPONSE(3): Name: UDLV_RESPONSE Identity:
1-1 :[711]:SET VARIABLE UDLV_OFFSET: 0
1-1 :[712]:SET VARIABLE UDLV_TEMP: {"error":"Key not available"}
1-1 :[713]:SET VARIABLE UDLV_OFFSET: 12
1-1 :[714]:SET VARIABLE UDLV_BVSESSIONID: y not available"}
1-1 :[715]:LOG: BV session id :y not available"}

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #707167 - 05/16/12 09:27 AM

You have read the doc, but you do not understand it. Slow down. Try to read and understand WHY the subroutine does what it does.

You do things like reference a global variable UDLV_bvsessionid before you put a value in it

PRIMARY GET URI &
"http://ambujawstest:8080/cmfrwk-webmvc/" &
"shiptopartylist.json?JSON_KEY="+UDLV_bvsessionid+"&1323348930=22-17" &
"-1337147044027&_search=false&nd=1337147084258&rows=-1&page=1&sidx=&sord=asc HTTP/1.1" ON 3 &
HEADER DEFAULT_HEADERS &
,WITH {"Accept: application/json, text/javascript, */*", &
"Accept-Language: en-us,en;q=0.5", &
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7", &
"Connection: keep-alive", &
"X-Requested-With: XMLHttpRequest", &
"Referer: " &
"http://ambujawstest:8080/cmfrwk-webmvc/createorder.do?menuid=64&1323348930=21-9-1337147044027", &
"Cookie: "+cookie_1_0}

Load Response_info Body on 3 Into UDLV_response
Set UDLV_offset =0
Set UDLV_temp = ~Extract(UDLV_offset, 1988, UDLV_response)
Set UDLV_offset = 13 + ~Locate("BV_SessionID=",UDLV_temp)
Set UDLV_bvsessionid = ~Extract(UDLV_offset, 29, UDLV_temp)
Log "BV session id :", UDLV_bvsessionid

Furthermore, you are using a logic that extracts a sub-string based using delimiters from the example.

what does the ~location function do? What parameters does it take? Do the parameters you passed it make sense?

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: Bernie Velivis]
      #707242 - 05/16/12 11:46 PM

Yes you are right Bernie i am not able to understand it.
How to deal with these functions:
Load Response_info Body on 3 Into UDLV_response
Set UDLV_offset =0
Set UDLV_temp = ~Extract(UDLV_offset, 1988, UDLV_response)
Set UDLV_offset = 13 + ~Locate("BV_SessionID=",UDLV_temp)
Set UDLV_bvsessionid = ~Extract(UDLV_offset, 29, UDLV_temp)
Log "BV session id :", UDLV_bvsessionid

why UDLV_offset=0, what is 1988, 29, 13. How to find exact location of the string. How to capture left and right boundaries of the string. I am helpless, can you please help me out??

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: pawanr]
      #707251 - 05/17/12 01:25 AM

I got, this is my new code, where 9 is JSON_KEY length i.e. LB and 48 is JSON string length, am i right Bernie?? but i don't understand what is 1988. I got same error i.e. key not available.

Load Response_info Body on 3 Into UDLV_response
Set UDLV_offset =0
Set UDLV_temp = ~Extract(UDLV_offset, 1988, UDLV_response)
Set UDLV_offset = 9 + ~Locate("JSON_KEY=",UDLV_temp)
Set UDLV_bvsessionid = ~Extract(UDLV_offset, 48, UDLV_temp)
Log "BV session id :", UDLV_bvsessionid

--------------------
Cheers,
Pawan R


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #707329 - 05/17/12 10:29 AM

http://opensta.org/docs/sclref10/imp3ln51.htm

~EXTRACT Command

Description:
This command is a function and can only be referenced within a SET command. It returns the portion of the source string identified by the specified offset and length.

If the string identified by the offset and length overlaps the end of the source string, only the characters up to the end of the source string will be returned.

If the offset does not lie within the bounds of the source string when the script is executed, a message will be written to the audit log, indicating that a bad parameter value has been specified. Script execution will then be aborted, or the specified action taken if error trapping is enabled via the ON ERROR command.

Format:
~EXTRACT (offset, length, string)
Return Value:
The character substring extracted from the source string.

Parameters:
offset
An integer variable or value defining the offset in the source string of the first character that is to be extracted. The first character of the source string is at offset zero.

length
An integer variable or value defining the number of characters to extract to form the substring.

string
The character value or character variable from which the substring is to be extracted.

Example:
SET NameCode = ~EXTRACT (0, 4, Name) + RunningNo
See also:

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: Bernie Velivis]
      #707334 - 05/17/12 10:42 AM

Here is a more detailed explanation of how to extract data from a response using a subroutine.


http://www.sqaforums.com/showflat.php?Ca...true#Post630530

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
pawanr
Member


Reged: 10/03/11
Posts: 87
Re: json key in client side java script [Re: Bernie Velivis]
      #707540 - 05/21/12 01:15 AM

Hi Bernie, After some research i found that jqGrid is responsible to display json data and jqGrid is nothing but client side javascript. jqGrid doesn't reflect in opensta script. Is it possible to handle jqGrid in opensta. There is no need to correlate json_key. Please find below mentioned sample source code Part:

<script type="text/javascript">
jQuery(document).ready(function (){
jQuery("#customerList").jqGrid({
url:"/cmfrwk-webmvc/customer.json?JSON_KEY=-441814886627341669779325711596693353898098819056&1573568944=18-17-1337587667210",
datatype: "json",
colNames:['Active','Group','Name', 'Customer code','Email','Sales Organisation','Dist Channel','Sales office','Sales unit'],
colModel:[

Is it possible to deal with jqGrid so that i can able to execute script?????

--------------------
Cheers,
Pawan R

Edited by pawanr (05/21/12 04:55 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bernie VelivisModerator
Moderator


Reged: 06/02/03
Posts: 1604
Loc: Hollis, NH, USA
Re: json key in client side java script [Re: pawanr]
      #707562 - 05/21/12 06:03 AM

No, OpenSTA will not execute js for you. OpenSTA will allow you to EMUALTE js running. Your tools to do this are correlation (which is usually all that is required) or writting more complex login using SCL (rarely needed).

--------------------
Bernie Velivis, Performax Inc
Bernie's blog


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 3 anonymous users are browsing this forum.

Moderator:  SteveKay, AJ, dansut, Bernie Velivis 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 7451

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5