Forum Discussion

pravin_k99's avatar
pravin_k99
Contributor
10 years ago

How can I use OnLogError event to execute the same statement again and not log an error

Hello



I know, OnLogError even it fired before the error is logged on to the log. but I want to achive below mentioned scenario. Can someone help please



- Whereever there is an error - which occurs because Object Not Found

- I want to run a script routine for example - myobject.refreshmappinInfo

- And the same statement again which caused the initial error



Thanks

Pravin

8 Replies

  • jose_pita's avatar
    jose_pita
    Super Contributor
    I don't think that's possible...



    Can't you make a loop looking for the object and only continue when you find it?



    while(!object.Exists)

    {

      look for object

    }
  • karkadil's avatar
    karkadil
    Valued Contributor
    I agree, this is not possible, but this is a good feature to have.



    Tanya, could you please register this request with 2 votes?



    The idea is to be able to run inside the Event Handler the statement which fired the event (smth. like reraise statement).
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    This is actually possible to do...



    JScript example:




    function main(){


    Log.Error('I won\'t log anything I promise :)!');

    }




    function dosomething(g){

    wshell = new ActiveXObject('WScript.Shell');


    wshell.popup(g.str);

    /* of course you would need to have handling to call back the function being

    performed but hopefully you get the point from this basic example */


    }


     


    function onlogerror(s,g){


    g.Locked = true;


    dosomething(g);


    }

  • karkadil's avatar
    karkadil
    Valued Contributor
    Ryan, the idea is to automatically rerun the statement which caused the error, not to call a function.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Yes I understand that. So you add your own handling. Which you would have to do regardless to avoid endless loops and such.






    function main(){


    try{


     Log.Error('hi i am an expected error');


     }


    catch(e){


     Log.Error('hi i am an error that was unexpected');


     }

    }




    function onlogerror(s,g){


    g.Locked = true;


    dosomething(g);

    }




    function dosomething(g){


    switch (g.str){


     case 'hi i am an error':


      main();


     break;


     case 'hi i am an error that was unexpected':


      trysomethingelse();


     break;


     }


    wshell.popup(g.str);


    }


     


    function trysomethingelse(){


    //do something else


    }





  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    There are several ways to do this I'm just providing a simple example for purpose of conceptual design. In my scripts I use a standard set of functions that drive the application(s) back to a point that scripts are able to resume from. I.E. Restart all applications, login, get back to the main form, resume where I left off.
  • Thanks Jose,



    But I cant add If Exits for eash step as I have around 10,000 objects mapped and several hundred tests using them



    Its just that due to the performance of the VM we are running the test on, sometime the object come into memory a little late. Hence when the object is not found, I wanted the test to not stop rather just retry the same statement again.



    Thanks Ryan/Gena



    I shall try to see if I can implement something like this.  



    BTW. can you please send me the VB Script version of a script, which catched the error and then goes back to same step which caused it. I just want the execution control to be transferred to the same place once, if it fails again then there is a genuine problem with the object and it can fail the next time.



    Thanks

    Pravin
  • jose_pita's avatar
    jose_pita
    Super Contributor
    I don't use name mapping, I always use the same function to click any object with parameters such as objectPropertyName and objectPropertyValue accepting arrays too (just did this in a hurry, can have some mistakes)





    function waitForObjectAndClick(objectPropertyName, objectPropertyValue, maxTime)

    {

    //maxTime is in seconds

    if(maxTime == undefined)

    maxTime = 5

    var obj,counter;

    counter = 0;

    while(!obj.Exists || obj == null || obj == undefined)

    {

    obj = sys.browser.page.find(objectPropertyName,objectPropertyValue, 30, true);

    delay(1000);

    counter++;

    }

    if(counter==maxTime)

    {

    Log.Error("UPS!");

    Runner.Stop();

    }

    }