How to use Python in Katalon Studio

I’ve made a sample project demonstrating the ability to use Python with Katalon Studio. There were some requests for adding Python support to Katalon Studio - I hope this sample will help.

Usage

  • Install Python (I’m using Python 2.7).
  • Under the python directory, execute pip install -r requirements.txt to install Python dependencies.
  • Execute Test Suite All.

How it works?

  • Test Cases are still written in Groovy using built-in and custom keywords.
  • Custom keywords make use of the PythonKeywords#runPython(runPython(String script, Object[] keywordArgs) to delegate the implementation to Python scripts in python/modules/keywords.py.
  • The Python WebDriver instance is retrieved using driver = utils.get_driver(allArgs). This instance connects to the Selenium session initialized by Katalon Studio. It will enable mixing Python-based keywords with Groovy-based ones. Also, the capabilities will still be managed by Katalon Studio.
  • Reports, listeners, and integration will behave as usual.
9 Likes

Nice job. Thank you, Alex.

1 Like

Thank you for sharing that approach. But shouldn’t Jython make it easier to at least use Python libraries in Katalon Studio? The requirement to install Python first is unfortunately not always possible in a third-party Selenium Grid environment.
I’m not familiar with it yet, but in the docs you’re talking about using Jython in Katalon Studio yourself: https://docs.katalon.com/faqs/features.html.
Unfortunately, I can’t find a suitable contribution to this approach anywhere. Could you please give me some hints on first steps?

Hi Alex,
thanks for the demo project - i had tried it but I am lost on where to check the logs and output.
test case Hello world => i could not figure out where the stdout is supposed to go ? logs located under /tmp/ are empty

{“keyword”:“keywords.hello_world”,“keywordArgs”:[11,15],“outputPath”:"/tmp/ks_py_output_2524097923715452990.tmp"}
ls -l /tmp/ks_py_output_2524097923715452990.tmp
-rw-r–r-- 1 vhuteau vhuteau 0 mai 17 15:37 /tmp/ks_py_output_2524097923715452990.tmp

also test case go to google is NOT opening the URL ; i only see firefox window opening and closing

I am running Katalon 6.1.5 on Linux Ubuntu 18.04
could you please help me understand how the python script is executed and where to find the logs of the python ?
thanks a lot
Nga

Let me try this next week - I was using Windows.

hello,

how to return value to test case?

Hello,

I would like to know if we integrate Python to Katalon, that’s mean we can write scripts, and execute them with Python, or juste the Custom Keywords will change with Python instead to Groovy?

Thank you

hi,

I tried, but not able to get results
2020-04-18 13:12:14.653 DEBUG testcase.passToPython - 9: demo.PythonKeywords.helloWorld(11, 15)
2020-04-18 13:12:15.134 INFO com.kms.katalon.core.util.KeywordUtil - [11, 15]

where the result should be seen
using python 3.7

i guess this is not support py3?

hello,

ouh, was typo in python script, now works fine :grinning:

1 Like

hi,

i did some changes to PythonKeywords script, now it’s return valu(s) to testscript

			def retval = []
			def input = new BufferedReader(new InputStreamReader(process.getInputStream()))
			while ((line = input.readLine()) != null) {
				KeywordUtil.logInfo(line)
				**retval.add(line)**
			}
			input.close()
			return retval

Hello @devalex88,
I want to add .py file into my test case is that possible?

Katalon script mode accepts Groovy/Java code.

Python is not supported. There is some talk about it, but the current version (6.1.5) doesn’t support it yet. There is a workaround here if that helps.

1 Like

@devalex88 Hi :slight_smile:
(macOS, python 3.7), what you mean “execute” test suite All,
I got that:
am I do something wrong ?

➜ Test Suites ./All.groovy
./All.groovy: line 1: import: command not found
./All.groovy: line 2: import: command not found
./All.groovy: line 3: import: command not found
./All.groovy: line 4: import: command not found
./All.groovy: line 6: import: command not found
./All.groovy: line 7: import: command not found
./All.groovy: line 8: import: command not found
./All.groovy: line 9: import: command not found
./All.groovy: line 10: import: command not found
./All.groovy: line 11: import: command not found
./All.groovy: line 12: import: command not found
./All.groovy: line 13: import: command not found
./All.groovy: line 14: import: command not found
./All.groovy: line 16: import: command not found
./All.groovy: line 17: import: command not found
./All.groovy: line 18: import: command not found
./All.groovy: line 20: import: command not found
./All.groovy: line 22: import: command not found
./All.groovy: line 23: import: command not found
./All.groovy: line 24: import: command not found
./All.groovy: line 25: import: command not found
./All.groovy: line 27: /Applications: is a directory
./All.groovy: line 28: All.groovy: command not found
./All.groovy: line 29: */: No such file or directory
./All.groovy: line 31: /Applications: is a directory
./All.groovy: line 32: All.groovy: command not found
./All.groovy: line 33: */: No such file or directory
./All.groovy: line 34: syntax error near unexpected token skipped' ./All.groovy: line 34: @SetUp(skipped = true) // Please change skipped to be false to activate this method.’
➜ Test Suites