So I’ve been experimenting with Katalon recorder as a means of a quick dirty task, ones I don’t want in my automation framework.
For the most part, I’ve not ran into any issues but I’m struggling to pinpoint to why my extension script when executed, that is not storing the returned value into the variable of “x”
The log message shows as below:
[info] Executing: | storeRandomString | | x |
[info] Store ‘RandomValue’ into ‘’
My js file is as below:
Selenium.prototype.getRandomString = function () {
var length = 5;
var chars = 'aA';
var mask = '';
if (chars.indexOf('a') > -1)
mask += 'abcdefghijklmnopqrstuvwxyz';
if (chars.indexOf('A') > -1)
mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (chars.indexOf('#') > -1)
mask += '0123456789';
if (chars.indexOf('!') > -1)
mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
var result = '';
for (var i = length; i > 0; --i)
result += mask[Math.round(Math.random() * (mask.length - 1))];
return result;
}
Any help in understanding why would be brilliant!!
Additional
withing my script you can see I’ve hardcoded the length and the chars, I was originally looking at passing in those two values, for example
`Selenium.prototype.getRandomString = function (length, chars) {
But looking at the docs for extension scripts examples, and searching the web, I wasn’t able to see any examples of how you pass the two parameters, i’ve seen examples with just one parameter. if any could show me via the target from within the recorder, would be brilliant!
Yeah, I tried that, which it just craps out the plugin , in which I had to restart the plugin…
Thank you.
But if you have any suggestions on how I can stop it crapping out when adding the script to the target that would be awesome? that’s if you get it working that way.
Yeah i tired the examples provided within the documentation, which work via extension scripts, i havent tired extracting this to target, but i suspect its teh amount of code entered to why it craps out.
Yeah this works in the console and works via extension script as it returns the value, just that katalon isn’t saving it to a variable that I set, just says: [info] Store ‘RandomValue’ into ‘’
where “RandomValue” is the value returned in this case. just weird as I’ve followed the examples and documentation, which suggest i must be missing something for which katalon is expecting in the recorder, or infact it just isnt possible?
So for some bizzare reason, the extension script needs a target for the command for it to actually save it to the variable… so its as it needs a hook into it, to store the return value.
Strange, but working now…
Solution was just to remove the hardcode length, and pass that via the target instead, so now it shows as below:
Would be curious still how to pass two parameters via a target, and if any one could expand on why it has to be done this way with the issue i had above, just havent seen anything in the documentation on the matter, will take another look though.
to pass 2 parameters or more try to just separate them with “,” it’s should be passing as a string or try to use “” to be sure it’s string then in your script use split
That doesn’t seem to be the case, though you’d assume it would be, I will take a look around and see if anyone else has asked a similar question. Thanks.