How to call the plug-in keyword in my project's custom keyword

Hi …
@Russ_Thomas @kazurayam @duyluong

Below is an example. How to call the plug-in keyword in my project’s custom keyword.

// Normal TC- find web element by angular
WebElement fn = CustomKeywords.'com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy'(ByAngular.model("person1.firstName"))
fn.sendKeys("Fred")

You show us a code, that’s all. So, what?

What are you asking us to do?

Hi @kazurayam

Firstly … I have installed the waitForAngularLoad Keywords from Katalon store. It has three keywords as show in the screenshot.

It’s very straight forward to use this Angular keyword in TC.
image

My question is how to use it my custom keyword.

For example: I wanna use the method findWebElementBy(ByAngular.model(“person1.firstName”)) in my custom keyword.

It seems you know it already, don’t you?
I can not see what’s your question.

Try:

com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy as ngFindWebElementBy

ngFindWebElementBy(...)

Maybe it’s static? Then import static ...

Pls excuse my ignorance :frowning_face:

Hi Russ, Thanks … I didn’t have luck. I am not sure … what I am doing wrong.

I tried using static import.

Ultimately I want to use the below in all my custom keyword i.e…
waitForAngularLoad()

CustomKeywords.'com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.waitForAngularLoad'()

Also I don’t understand this part as highlighted in bold " findWebElementBy as ngFindWebElementBy"

com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy as ngFindWebElementBy

Also in your previous post … I don’t understand what mm stands for …

import static my_package.my_class.my_method as mm

// call my_method
mm( /* your args here */)

the form import com.some.very.long.stuff as shortName will simply allow you to use it shorter in the code, so instead of writing everytime:

com.some.very.long.stuff.someMethod()

use:

shortName.someMethod()

Hi @bionel In the above import statement What does “as mm” means?

doesn’t’ matter. you can put whatever you like after as and use it accordingly later in your code.
but if i have to guess i will say mm stands for MyMethod :stuck_out_tongue:

Thanks @bionel for clarifying …

On the other hand how to use this Katalon Angular plugin keyword in my custom keyword?

@discover.selenium

You attached the following screenshot in the original post 2 days ago.

Here I noticed that findWebElementBy is underlined. The underline implies that Katalon Studio regards this piece of code invalid, and therefore this code would not work. Why is findWebElementBy underlined?

Is it what you are asking to us?

1 Like

If it is what you are asking, I can find an answer.

The javadoc of this plugin is published here. In the doc, I found findWebELementBy method is an instance method; it is not a static method.

In your Keyword implementation, you are calling the method as if it is a static method:

com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy(...)

But, as the javadoc tells, the method is not implemented static , therefore Katalon Studio warned by putting an underline on findWebElementBy.

Rather, in a Keyword implementation you should create an instance of WaitForAnglarKeywords class, and call its method like:

import com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords
...
WaitForAngularKeywords instance = new WaitForAngularKeywords()
WebElement fn = instance.findWebElementBy(ByAngular.model(...))
...

@ThanhTo

I think that the findWebElementBy method of com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords class should be declared as static. There would be no reason not to do so.

1 Like

By the way, in a Test Case script, you can write:

WebElement fn = CustomKeywords.'com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy'(ByAngular.model("person1.firstName"))

and it would actually work.

Here I feel confused: CustomKeyword’s syntax is too similar to calling a static method named findWebElementBy, but it is not necessarily a static method. Katalon’s CustomKeywords hides the difference between a static method and an instance method. Is it a good design or not? I am not sure.

But when a user tries to use the plugin class in a context of Keyword class == out of CustomKeywords in a Test Case, the difference matters. Should he/she call the method as an instance method or a class’s static method in a Keyword class? How he/she can find the answer? The only way for them is to read the javadoc and think deep.

1 Like

Yes kazurayam … Thanks for your detailed answer …

In your code, I found findWebELementBy it is not a static method rather it’s an instance method;.

In your code you are calling method as a static method:

com.katalon.plugin.keyword.waitforangular.WaitForAngularKeywords.findWebElementBy(...)

Meanwhile the method is not implemented static, hence Katalon Studio warned by showing an underline in findWebElementBy method.