Can i use java programming language in katalon studio?

Hi,
please help me
Can i use java programming language in katalon studio?
If yes please show me an example

Hello,
yes, you can. Katalon Studio is using groovy as engine for their scripts. Just google Java and Groovy.

I have the same problem!

Custom keyword = Java class
Test case = Groovy script

2 Likes

Hi Giri,

We can give u a lot of examples but could you be more specific on what kind of example do you need?

1 Like

Yes, you can use Java in Katalon.

To elaborate, when you are writing scripts and/or custom keywords, you can write them in either Groovy or Java syntax. Groovy is simply a language that “extends” the Java language, and has the benefit of being a simple and powerful scripting language (among other benefits).

This means that when you write something in Java, it is automatically valid Groovy code (with a very small set of exceptions). So feel free to use Java everywhere if that’s what you’re more comfortable/familiar with. That’s what I do as well and it works beautifully :slight_smile: For example, my scripts generally look something like this:

I found it very very easy to implement the page object model with Java, which the script snippet above uses heavily.

3 Likes

for any of the login page like gmail or facebook in java

Hi Giri,

Java code in Katalon Studio works like coding in NetBeans IDE. It also works without semicolon at the end of every line.

You can refer to the code below for a simple login code:

//import WebElement and JUnit for Assertion, same as how you do in Java
import org.openqa.selenium.WebElement
import junit.framework

//just use WebUI keyword for launching the browser, it's more convenient rather declaring a WebDriver
WebUI.openBrowser("https://www.facebook.com")

//Locate your object
WebElement uName = WebUiCommonHelper.findWebElement(findTestObject("Login_Text_Field"), 30)
WebElement pWord = WebUiCommonHelper.findWebElement(findTestObject("Password_Text_Field"), 30)
WebElement btnLogin = WebUiCommonHelper.findWebElement(findTestObject("Login_Button"), 30)

//do checks
uName.isDisplayed()
uName.isEnabled()

pWord.isDisplayed()
pWord.isEnabled()

btnLogin.isDisplayed()
btnLogin.isEnabled()

//do events
uName.click()
uName.sendKeys("your_Username")
String uNameFieldValue = uName.getText()
Assert.assertEquals("Your_Username", uNameFieldValue)

pWord.click()
pWord.sendKeys("your_Password")
String pWordFieldValue = uName.getText()
Assert.assertEquals("Your_Password", pWordFieldValue)

btnLogin.click()

Hope that helps. . . :slight_smile:

2 Likes

yes thanks a lot.

and one more question can we pass objectsrepository/objects in groovys findtestobject() method.

i want to do same thing in java. any example foe this?

Hi @giri.gowda.5

If you have object ID as a string then you can pass it into the findTestObject method. The function will return a TestObject instance so that you can have further use.

Cheers !

thanks and working

Hi Arnel. Is this code for a test case or a custom keyword? Thanks.

Hi Brandon. Is this code for a test case or a custom keyword? Could you please provide some references to using POM in Katalon? Thanks.

Java code can be used in both. The POM would be built using custom keywords, and your scripts would utilize those keywords.

Thank you Brandon. I was asking because of the quoted post above. So, now I know that Java code can be used in both. What would be the best practice? Is that really “Custom keyword = Java class
Test case = Groovy script”? And again is this code for a test or a custom keyword?

Thanks.

It’s a matter of preference. I do everything in Java because I’m more familiar with that language, but you can mix/match wherever you would like.

That particular example is from a script, where it’s referencing Page Objects that I’ve set up (using Keywords).

Thank you Brandon. I have a lot of experience with Java but not with Groovy. That’s why, even though Groovy is similar to Java (but not the same), my first instinct is to use Java. On the other hand, I’m totally new to Katalon (actually, I’m just about to start evaluating it), and I can see that by default both tests and custom keywords are in Groovy. So, there must be some reasons for setting Groove as the default programming language in Katalon. And, actually, I don’t even know how to switch it from Groovy to Java.
Any words of advice for a total newbie ?

The only reason would be that Groovy is considered more of a “scripting” language than Java is. In particular, it’s less verbose. Beyond that, there’s really not that many differences that matter.

There’s no setting to “switch” between languages, the two are symbiotic, meaning you can even write in both languages in the same script if you wanted to. The Groovy language simply extends (sits on top of) the Java language. You can think of it as a particular “flavor” of Java even.

Thank you Brandon. So, I don’t have to do nothing specific to use Java in Katalon. I can just write Java code in the groovy files (i.e the files with .groovy extension). Correct? Do you happen to know on top of which version of Java Groovy sits in Katalon? Java 8 or higher? And one more question (but, probably, a really stupid one)) is that possible to use Selenium library directly from Java code in Katalon? I’m asking because I know how to do some things by using Selenium library but don’t know whether the same can be done in Katalon (e.g. scrolling, JavaScript execution, etc.)

@gdearest07

If you’re proficient at Java then you can just think of Custom Keywords as Java classes. Katalon recognizes the annotation @Keyword and parse these Java classes into the so-called Custom Keywords which are more intuitive to use in the Manual view of test cases.

Currently Katalon supports Java 8.

Yes, Selenium API jar are already available in Katalon. Just import them into your test cases.