Custom Keywords no longer working after Katalon 7 Update

I have Tested this issue on Katalon 7 and the previous version prior to update by downgrading, The issue is only present when using Katalon 7.

Issue:
When Within my katalon Project and trying to execute a Test, After updating to Katalon 7, my ‘CUSTOM KEYWORDS’ are no longer working. Katalon log shows that the Keyword was executed without issue, but I can see clear as day the action did NOT take effect.

Custom Keyword:

> package test_keywords
> 
> import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
> import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
> import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
> import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
> 
> import com.kms.katalon.core.annotation.Keyword
> import com.kms.katalon.core.checkpoint.Checkpoint
> import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
> import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
> import com.kms.katalon.core.model.FailureHandling
> import com.kms.katalon.core.testcase.TestCase
> import com.kms.katalon.core.testdata.TestData
> import com.kms.katalon.core.testobject.TestObject
> import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
> import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
> 
> import internal.GlobalVariable
> import com.kms.katalon.core.webui.driver.DriverFactory
> import org.openqa.selenium.JavascriptExecutor
> 
> 
> public class test {
> 	def static String makePCRURL() {
> 		return 'https://' + GlobalVariable.Server + '/pcr.asp?uid=odbc.' + GlobalVariable.Profile + '&disablecontrols=true'
> 	}
> 
> 
> 	@Keyword
> 	def fixSelectElements() {
> 		((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(
> 				'''
> doOnIframe(document, -1);
> 
> function hideComboShowSelect(currentFrame){
>     console.log("@ " + currentFrame.src)
>     if (currentFrame.contentWindow){
>         var fastcombos = currentFrame.contentWindow.document.getElementsByClassName("fastcombo");
>         var selects = currentFrame.contentWindow.document.getElementsByTagName('select')
>     }
>     else {
>         var fastcombos = document.getElementsByClassName("fastcombo");
>         var selects = document.getElementsByTagName('select')
>     }
> 	Array.prototype.forEach.call(fastcombos,function(fastcombo){
> 		$(fastcombo).hide();
> 	});
> 
> 	Array.prototype.forEach.call(selects,function(select){
> 		$(select).show();
> 	});
> }
> 
> function doOnIframe(currentFrame, index){
>     
>     var selectedFrames = currentFrame.querySelectorAll('iframe');
>     try {
>         if (selectedFrames.length != 0){
>             selectedFrames.forEach(function(iframe, i){
> 
>                 doOnIframe(iframe, i);
>             });
>         }
>         console.log("iframe " + "iframe.miniframe.minimodal" + currentFrame.id + " " + index);
>         hideComboShowSelect(currentFrame);
>     } catch(error){
>         //do nothing
>     }
> }
> 		'''
> 				)
> 	}
> }

If I downgrade my Katalon to version 6.3.3. and I execute my test, The keywords function properly. Has anyone come across this issue where your Custom Keywords are not being actually executed but Katalon says the custom keyword step

test_keywords.test.fixSelectElements is PASSED

I’m using KS7 with 500 gazillion custom keywords just fine.

You may want to reconsider this:

} catch(error){
    //do nothing
}

Hi Russ,
I am glad that you are not having the issue. Sadly that does not mean I and others are not =/ I removed my Catch but that didn’t fix anything, Furthermore I am not sure why that would cause an issue in Katalon 7 and not Katalon 6.3.3. if that WAS the issue.

I can actually take the same JS that is within the Custom Keyword and run it within the Google Console, and the effect of my Custom Keyword happens without issue. The only time I see it NOT work is when I am telling Katalon to preform the JS for me.

This is not website related, So the question becomes, When YOU run your Custom Keywords, Are you ever preforming actions such as I am? Are you using Chrome Browser? Are you running Katalon on Windows of MAC, What version of Chrome are you using? What OS are you using? What version of Java are you using? There is clearly something within Katalon 7 that is not liking my keyword as the issue is NOT present in an earlier Version.

If you need additional information please let me know. Thanks!

I wondered if there was an error that it was preventing you from seeing.

I use tons of JS too. Weird.

No. Firefox.

Win7 and Win10

Let’s see if it’s a JS issue first. Put this in a new test:

Here’s the code to scrape:

String js = """
      console.log("This is JS");
    """
WebUI.executeJavaScript(js, null)

Check the browser console for the output.

Watch that quote typo in my screenshot - code block is fixed. :blush:

image

Just to add, I’ve gone over your “frame-walker” code (good name?) and, FWIW, I can’t see anything wrong with it (but I’m not a JS engine :wink: )

Seriously, it looks good to me.

If that pokey bit of JS I gave you works, we need to consider the Keyword/Class/Methods as having an issue. You could try a very basic chunk of JS in a new Keyword and test that in isolation.

Let me know.

No problem at all. Okay So I have preformed the test and I am seeing this work. Now The test I would like to do is create the same Test in an earlier version of Katalon, then upgrade and see if there is an issue with keywords that were NOT created within Katalon 7.

Good test. I’d try my next step first. Doesn’t really matter though…

Could you please add some alert() or console.log() to see if the JavaScript code did execute?

I have tested this issue for a few days now and I believe I have found what is causing the issue. It looks like the issue is only present when upgrading to 7 and using keywords that were created in an earlier version. I was able to recreate the keyword in question by copy and pasting into a new keyword and the issue was no longer present. So as a work around I was able to simply recreate the keyword via Katalon 7 and all worked without issue.

1 Like

Weird. All my many keywords were created in v5 or v6 – I have just a few created in v7. They all work fine.

To be clear: I don’t use @Keyword and I don’t call keywords using Manual view. All my keywords are imported statically into test cases.

Thanks for reporting and your own digging @Joseph_Coverstone. @Russ_Thomas that could be the distinction, most users will probably use the @Keyword. I will check with the team for further investigations and let you guys know !

1 Like

Thanks ThanhTo,
Please keep me posted as I do not really want to have to go back and recreate all my @keywords. I am pretty sure @keywords is the issue here. I am with you on the fact that MOST users are probably using the @keywords vs just implementing their JS into their script every time they want to call on them.

That’s not what @ThanTo meant. The comparison is between declaring a keyword with the @Keyword decorator/annotation and using Keyword methods directly by importing them statically. This has nothing to do with using JavaScript in Groovy.

I duck out now to avoid any more confusion.

@Joseph_Coverstone

I cannot reproduce this issue, either with @Keyword or statically call the keyword function. Since you mentioned you looked into this on your project, does the scope of the observed effect (not working keywords) also includes Custom Keywords that do not use Javascript ?

A small experiment, disable the Smart Wait Execution in Project > Settings > Execution and execute the test which used the Custom Keywords developed in the earlier versions to see if it works.

Another experiment, inspired from @Russ_Thomas answer to a recent question in which the Test Listener was behaving erratically, is to try disable the "Auto Restore … ", then re-open the project that used the Custom Keywords developed in the earlier versions and execute the test again. Who knows what voodoo can we observe again.

1 Like

Okkkkaayyy well I have managed to completely break Katalon.

Here are some things I have been getting since messing with settings.

Issue #1:
Browser will no longer open using “Open Browser” if The following Imports are present in my script Which they have always been part of my script

“import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject”

Issue #2:
When looking at the Script view of my Test case that I am attempting to run, I am noticing that the Custom Keyword that is inserted into my script does not stay pink like it use to . See image

Issue #1:

Are you sure ? Windows Keywords were introduced only recently.

Issue #2

If you switch to the Manual mode, then add the custom keywords from there then does it work ?

Hi ThanhTo,
Unless Katalon adds Imports to existing tests when Katalon updates, the Imports have always been there for my tests. Now the scripts when I add them, I normally add them via the Manual Mode then I view them in the scripts mode to make sure everything looks okay. So to answer your question, the Custom Keywords were added to my test via Manual Mode and not Script mode. :slight_smile:

@Joseph_Coverstone, I also have had issues after trying to update to Katalon 7. Tried several times with a few different projects. Some had issues and some didn’t. One project, when I tried updating a second time with the same build of v7 it worked. Tried lot’s of troubleshooting tips from suggestions in the forums, but no luck. Tried it on 3 different computers (Win 10). Could not waste any more time now, so just went back to v6.3.3 which all projects work perfect in. I did create a new project in v7 and created several of my keywords in it and did not have any issues.

Hope you have better luck than me with upgrading to v7.

Are you running the project using KS 6 or KS 7? Projects saved by KS 7 must be executed by KS 7 or Katalon Runtime Engine 7. If you want to use KS 6 again, please remove all import statements containing com.kms.katalon.core.windows.

It should be pink by default in KS 6.