Tuesday, March 9, 2010

Loadrunner - Ajax(Click & Script) - EvalJavaScript, EvalJavaScriptResultParam

Loadrunner - Ajax(Click & Script) - EvalJavaScript, EvalJavaScriptResultParam

Select AJAX(Click & script) protocol if your application contain Ajax functionality.

AJAX (Asynchronous java and XML) is preferred solution for creating fluid applications with advance user interactivity. Traditionally browser use GET and PUT method to refresh entire page for every interaction with the server, this would create load on server and network. By using AJAX, browser and server exchange small amounts of data in (XML or JASON format) asynchronously in the background through XMLHttpRequest object with out reloading the whole page for every user action. Javascript code use the data received from the server and update HTML in browser DOM (Document object model) which contain all the elements of the browser session. 

By using very limited object properties, HP could implement QTP technology into this protocol.

Loadrunner will create corresponding Web_xxxxx function, when user perform actions on STANDARD web objects. It can't recognize third party objects, then we need to use Java script to emulate user actions.
Understand third party object methods, properties by looking at the page source code or interacting with the developer who created the page and create corresponding javascript code.

Attaching sample code for FCK editor and ULTRA web grid.

        web_browser("Java_Script",
            ACTION, 
            "EvalJavaScript= var oEditor = FCKeditorAPI.GetInstance('ctl00_cpheSupplier_txtNdaMessage');var oDOM = oEditor.EditorDocument;oDOM.body.innerText = 'Bharath';",
            LAST); 

        web_browser("Java_Script",
            ACTION, 
            "EvalJavaScript=igtbl_getRowById('ctl00xcpheRFxxUltraWebGrid1_r_16').getCell(7).setValue('999');updating = true;"
            "EvalJavaScript=igtbl_getRowById('ctl00xcpheRFxxUltraWebGrid1_r_17').activate();",
            LAST); 

Some time we may require to retrieve page DOM values. Attaching sample code that retrieve element properties into loadrunner.

    web_browser("JavaScriptCode", 
        DESCRIPTION, 
        ACTION, 
        "EvalJavaScript=var id = document.getElementById('message');EvalJavaScriptResultParam = id.style.display;", 
        "EvalJavaScriptResultParam=prmJavaScriptReturn",
        LAST);
    lr_output_message("%s",lr_eval_string("{prmJavaScriptReturn}"));  




----

6 comments:

  1. vijay garu,
    need a quick help in LR, am trying to write some error handling code,.
    I am currently assigned a task which i need to complete in 2-3 hours,
    I am tesitng a java based web application where i need to write a logic,.error handling..
    scenario 1:
    if a screen comes,. tell LR to click on ok button, if not, continue,.
    scenario:
    if the default page displayed is x, then proceed further in selecting the data,. if not, selected the page required.
    I can share my desktop to you to get a clear picture of the same,. and help me in resolving the issue.
    Best regards,
    ram.

    ReplyDelete
  2. Ram,
    I have sent an email on the same.

    ReplyDelete
  3. Hi Bharath,

    We have an applicaiton where lot of AJAX calls are happening in the background. Our requirement is to capture one of the such Java calls and to capture the time required from button click till that call. Do you have any suggestion?

    E.g. Click on Search Button retuns 8 Blocks of data (All are async calls). We need to capture the time between click on search and first block of data received and rendered on screen.

    Thanks,
    Pawan
    lpawan23@yahoo.com

    ReplyDelete
  4. Hi Bharath,

    I am newbie for LoadRunner, and I am using Ajax Click and Script protocol to test Ajax applications. I am able to record the application successfully, however when I reply my scrip it throws a lot of javascript errors like:- JavaScript error (id=22) in line 31: $ is undefined.

    Kindly suggest, as I am unable to find its solution. Do I need to put think time inbetween?

    Thanks

    ReplyDelete
  5. I am also facing same problem problem,

    during replay getting so many JS error and not doing action on button.

    And same scenario recording in IE9 using LR11.50 than on click of link getting one popup error "IE has been stop running".

    Please suggest me what should i do ....

    ReplyDelete
  6. Hi Bharath,

    I am facing a problem in bellow scenario during recording:
    Using - Windows 7 (64bit), IE9, LR 11.50, and 'Ajax -Click and script' Protocol.

    Application using Ajax functionality.

    Recording below scenario :
    1) Navigate to my application
    2) logged in with admin credential
    3) click on a link
    while recording clicking on any link, getting a popup error 'Internet Explorer has stopped working' Please find the error attachment.

    But Same scenarios Logged in as different credential than working fine ..... why its happening with admin credential ?

    Same scenario doing manually that also working fine.

    Can any one Please help me what exactly problem is :
    1) is it Recording setting issue
    2) IE setting issue
    3) Application issue
    4) or else

    I am unable to show u screenshot, i can send u in mail if u provide MailID ...

    Please help me out in same problem.

    ReplyDelete