Can I use JavaScript?

Can I use JavaScript on Katalon Recorder to identify elements not picked up by the recorder tool or to execute commands not supported by the recorder tool?

How do I go about using JavaScript on Katalon Recorder

You can use “runScript” and “storeEval” command. We also support custom action now http://forum.katalon.com/discussion/6286/we-have-released-katalon-recorder-3-5-0-with-support-for-extension-scripts-aka-user-extensions-js.

Hi there,

Could I get a good example of to use the Java scripts. Just mentioning use runScript and StoreEval is not sufficient. Alex could you explain how to use the examples mentioned for
sample-custom-commands and sample-locator-builders

Hello,

You can read it here.

Hi Alex,

Thanks for your reply. I am still finding it difficult to understand how to use user extensions.Js in the Katalon recorder. Could you give me two simple examples:

Example 1: How are we executing Javascript without any parameter in Katalon recorder.

Example 2: How are we executing Javascript with any parameter in Katalon recorder

Although we have Findlocator.js and sample-custom-commands.js but it has not been explained how to use them in the Katalon recorder script. Attached is snapshot where I have attempted to use Findlocator.Js


with regards,
Mubbashshir

Hi,

Please tell me what are you trying to do with Findlocator.js and I’ll help you troubleshoot.

Hi Alex,

Findlocator.Js has given below code in it which will find Y co-ordinate of a page object. I really want to know how to call this function in Katalon Recorder, You can see, I have made an attempt in the snapshot given above(last line of code) by using the given below line of code in Katalon Recorder but unable call the function
runScript Findlocator.js, id=comment

Can you give me example using https://katalon-test.s3.amazon.com/aut/html/form.html website. I have really spent lot of time to progress this any help will be appreciated

//Finds y value of given object
function findPos(obj) {
var curtop = 0;
if (obj.offsetParent) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}

Hi @mubbashshir.mohiuddi,

Here are the steps to use the script:

Step 1: Prepare a file, e.g. command.js.

Selenium.prototype.getPosition = function(locator) {
    var element = this.browserbot.findElement(locator);
    var curtop = 0;
    if (element.offsetParent) {
        do {
            curtop += element.offsetTop;
        } while (element = element.offsetParent);
    }
    return curtop;
};
  1. Add the file to Katalon Recorder.

Click on Add Extension Script button and select the file. Do not forget to refresh the browser tab you want to test.

  1. Prepare a script.

open | Demo AUT |
storePosition | id=first-name | position
verifyPosition | id=first-name | 182
verifyPosition | id=first-name | 18200

As you can see, from the function getPosition Katalon Recorder will automatically generate commands storePosition, verifyPosition, assertPosition to use in the script.

1 Like