Forum Discussion

sergi's avatar
sergi
Contributor
11 years ago

'JScript runtime error' doesn't trigger OnLogError

I'm having a problem with a script that makes the app under test crash and when it crashes it makes my script fail with a 'JScript runtime error'.



The problem is that the OnLogError event is not raised and there is where I store the errors ocurred during the execution.



Any suggestions?
  • chrisb's avatar
    chrisb
    Regular Contributor


    The test runner doesn't catch JavaScript runtime errors. You need to implement something yourself. You can put your test script inside a try catch block to handle them.



    function myTestScript() { 



    try {



          //test script



      } catch (e) {

          Log.Error(e);

      }



    }


  • chrisb's avatar
    chrisb
    Regular Contributor
    If the code you are calling the function from is inside a try catch block then you can catch the error if the function is in another unit. Its all about scope. Where are you calling your function from?

    See the example below. The test script is in a try catch block. It is calling a function in another unit in my project called 'library'. A javascript error is thrown during execution of the AddText function and is logged in the test log.




    //USEUNIT library



    function testScript(){



    //calls a function from library unit that is intentionally broken



    try{

    AddText("TextBox","123");

    }

    catch

    (e){

    Log.Message(e.message);

    }



    }


  • Hi Chris, I've tried a try..catch but it has to be placed in the exact failing function.

    It seems that the exception can't be catched from another Unit and that's not 100% convenient for me...

    Are you aware of any workaround?