@Keyword call gives error. Restarting Katalon solves the problem.

I’ve defined a @Keyword and it works well but there is a small issue.

This is the @Keyword.

--------------------------------------------------------------------------------------------------------------------

@Keyword




**def**  

smartWaitAndSendKeysMethod(String toPath, String SendTextKeys) {

   TestObject  

to = findTestObject(toPath)

   **for** (**int** j = 0; j <= 120; j++) {




       **if** (WebUI._waitForElementNotPresent_(to, 5) == **false**) {




           WebUI._waitForElementPresent_(to, 60)




           WebUI._waitForElementVisible_(to, 60)




           WebUI._waitForElementClickable_(to, 60)




           WebUI._sendKeys_(to, SendTextKeys)




           **break**




       }  

else {

           WebUI._comment_('Element >' + toPath + '< is still not  

present. Wait.’)

           WebUI._delay_(1)




       }




   }




}

--------------------------------------------------------------------------------------------------------------------

Adding an additional @Keyword call in my script source code:

CustomKeywords.‘com.ImprovedWait.NEW_Wait.smartWaitAndSendKeysMethod’(‘REPOSITORY/OBJECT’, “ABC”)

triggs an error:

--------------------------------------------------------------------------------------------------------------------

SCRIPT FAILED because (of) org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: com.ImprovedWait.NEW_Wait.smartWaitAndSendKeysMethod() is applicable for argument types: (java.lang.String, com.kms.katalon.core.testdata.InternalData) values: [REPOSITORY/OBJECT, com.kms.katalon.core.testdata.InternalData@22f59fa]

Possible solutions: smartWaitAndSendKeysMethod(java.lang.String, java.lang.String)

--------------------------------------------------------------------------------------------------------------------

as if the Keyword parameters were not defined as java.lang.String which they are.

Hovering over the @Keyword’s String parameters show that they are java.lang.String defined.

HOWEVER: Restarting Katalon makes the error dissapear and the script runs fine until next edit.

Is there something else that must be included or imported to the Script?

Apparently Katalon/Eclipse is reading/updating something vital at start. What?

The error is complaining about the types you’re sending – it’s telling you that you need to send two strings while you are sending a string followed by the type com.kms.katalon.core.testdata.InternalData

You could try a cast before the internalData, or append .toString() to the second parameter.

I am sending 2 strings and NOT following it with the type

(‘REPOSITORY/OBJECT’,‘ABC’)

Also: without changing the code it works fine tens of times after a Katalon restart.

As soon as I add a call it gives error again until I restar Katalon. Then it is ok.

I tried type casting and it doesn’t help.

Yes, I understood that. But the error statement is quite clear. If you’re convinced the scenario you describe is actually what is happening, then you have found a bug in Katalon/Groovy.

I would like to see ALL the code for the Keyword class, but I guess that’s not likely.

I would also like to repeat, you should use a static method as I showed you in the other thread. Then this problem will be avoided. Unless… there is a bug in your code somewhere not revealed by the snippets you’ve posted to the forum.

I could send you the code in a private message there are parts of the code (names) I can’t make public.

the reason I mentioned Eclipse is I read in another thread (can’t remember which) of an error that disappeared by restarting Katalon/Eclipse.

Regarding to be sure: when the error appears the ONLY thing I do to have it go away is restart Katalon. I now know I must do that as soon as I add a Keyward call otherwise error.

This is my Keywod code. If you need the Script code I can send it in a private message:

Keyword.txt

Firstly, I wish you would use static methods like I explained to you – your code will look cleaner (I don’t even need to see your test script code, I know what it looks like – bloated with stringized calls to the Keyword mechanism).

Secondly, I see you are using FOR loops controlled by IF statements. Generally, whenever you see that kind of pattern, it is usually better to make the whole thing a WHILE statement.

Thirdly, all of the WAIT APIs are commands that have a built in loop. That’s what the timeout argument is for. It does not make sense to place them all inside a loop of your own with one second delays, that is exactly what they’re doing already.

Lastly, good luck :slight_smile:

Thanks again, appreciate your help. I also will process your points of view regarding the quality of my coding. Also I will implement your recommended static methods.

HOWEVER:

  1. it would be interesting if someone else have experienced the Keyword error. (root cause?)

  2. I would like to know how Katalon Keyword functionality should be implemented (errorless).

PS: My coding as is fulfills all my needs, works perfectly, swiftly and with no errors (as long as no edited) or delays allowed me to clean all the Delay:s of my code. And mainly it REALLY waits for the element to be loaded. I perfectly understand that WAIT APIs have built in loops but they DO NOT always wait for the element to be loaded, they will click or send keys too early and the script will fail. My coding, with all the shortcomings that you rightfully have observed and probably other that you haven’t is doing the job and at the end of the day this is what I need.

PS2: I executed 200 loops of my test scenarios WITH NOT A SINGLE irritating error due to too-early-clicking and it takes the same time as with Katalon standard function calls. So the Keyword is doing it’s job waiting until the element is ready.

That’s fine in so far as you’ve attained the result you are expecting. However, if the APIs (with built in loops) are not functioning to your expectations, why are you using them inside your own loops? You’re plastering over what you think is broken code.

Create JavaScript methods that truly ask the page for state information, directly. Wrap those methods in loops. I promise you, you will never look back.

I couldn’t agree more with your words, you are totally right. And I thanks again for your help.

The reason I use the API’s with built in loops is because maybe (but only maybe) they are providing the little extra waiting time that is needed to do the job correctly. Yes. could someone argue, I could also use a straight Delay. Well, at the moment I am sticking to the old adage “if it works don’t mess with it”. and since it works I don’t mess with it. Unless I find something better that works.

In your same line of argumentation one could ask why am i using waitForElementNotPresent (which is a central piece in my Keyword, a piece that I cannot do without)… Well, the only thing I am doing is adding a repetition and that way IT WORKS while when using standalone wait for … Present … Visible … Clickable …, is not working (in hundreds or thousands of calls thru 200 loops) while the Keyword is rock solid and never fails.

Go figure.

I am pragmatic and stick to reality:

  1. Keyword is working (unedited). Don’t mess with it.

  2. Still don’t know how to correctly implement a Keyword.

Cheers!