Forum Discussion

Glottis's avatar
Glottis
New Contributor
8 months ago

How to debug JavaScript in Validations? Can I check variable values?

I'm not fluent in handling DOM elements. When I'm trying to write validation like (taken from https://support.smartbear.com/loadninja/docs/scripts/validations.html๐Ÿ˜ž
function isLoginButtonEnabled() {
  var button = document.querySelector("button.login-item");
  return (! button.disabled);
}
return isLoginButtonEnabled();
It will invariably fail multiple times because I got button name wrong, or my button was inside an iframe, or it wasn't a button at all etc etc.
So for me value of variable button will be "undefined" or contain value of a wrong button or some such.
Normally, I'd print variable values into log to see what I get, and then modify my code many a painful time until it actually returns what I need, but I don't understand how to do it for UI tests in LoadNinja as it doesn't look possible to write anything into Playback log.
So how do you debug? A code example would be much appreciated.

1 Reply

  • Glottis's avatar
    Glottis
    New Contributor

    Anybody?
    My trial is about to expire and I'm still unable to write a single working JavaScript validation.
    So much for "requires no programming" ๐Ÿ˜ž