Extension script at Katalon recorder doesn't work

hi,

I’m using Katalon (3.6.11) recorder (Ubuntu 16.04.4 LTS + Chrome 70.0.3538.67). I’ve tried to use the extension script as described at:
https://docs.katalon.com/katalon-recorder/docs/extension-scripts-aka-user-extensionsjs-for-custom-locator-builders-and-actions.html

I’ve used the example scripts with the URL that is used in the example:
https://katalon-test.s3.amazonaws.com/demo-aut/dist/html/form.html

I would have expected to have the same result as in the example:

but all I get is:

I’ve added a console.log to the extension and saw that the JS is being executed.
I do see the error:

“Uncaught (in promise) {message: “The message port closed before a response was received.”}”

but I’m not sure if that is the cause of the issue. I’m pretty sure the JS is executed but the return is not being used, any idea as to how to resolve this?

@devalex88 @YoungNgo @Zarashima

Can someone on the inside at Katalon please make sure that published articles and examples are actually working correctly?

Thanks.

2 Likes

Hi. I’m sorry for the late response and apologize for the document not make it clear enough.

In the sample scripts the order of locators is:

// built-in locators: "id", "link", "name", "dom:name", "xpath:link", "xpath:img", "xpath:attributes", "xpath:idRelative", "xpath:href", "dom:index", "xpath:position", "css"
LocatorBuilders._preferredOrder = ['xpath:position', 'my super locator'];
// Change the default order to preferredOrder
LocatorBuilders._orderChanged();

Therefore, the sample locator is the second item in the list:

The storeTextLength command is provided by the extension script, therefore it will not appear in the list of suggested commands. It has to be typed manually:

Also, don’t forget to restart Katalon Recorder and refresh the web page you want to work on after installing extension scripts.

hi @devalex88,

Thanks for the info, now it works as expected.
Just to clarify is there a test that is run on the returned value before it is added? a test that verify that the string can actually return a valid selenium element. If so can it be disabled?
I see that if I return a simple string “nope” it is not being registered.

No the returned locator is not validated. The locators must be in one of the supported forms:

  • <type>=<locator> where type can be id, name, link, css, xpath
  • //<xpath>

Were you trying to introduce a new locator type?

I recorded a session in a site that support multiple languages (session was recorded in English). Then I tried to reply it again on the same site with a different language. The test failed as the recorder used xpath + text, for example:

" driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)=‘lolz245’])[1]/following::div[5]").click()"

The recorded session will fail on any other language beside English.

So I have a script that tries to find multiple uniqueness of a selected element. So I was hoping to use the extension script in such a way: When an element is being interacted with I run my JS script on that element, then I register in the recorder the output of that script (false/array of matches).
Then I use the exported code to re run the steps on each language.

Is there any other locator type that suits your need? If there is, you can change the preferred order so that the above XPath will not be the first suggestion.