Reputation: 3
I am trying to call a Python function residing in a separate .py file from the Keyword section of a .robot file.
Is there any way to do that? Right now the function name residing in the .py file is not recognised from the .robot file.
a.py
Class abc:
def func:
...
x.robot
Library a.py
*** Keywords ***
Calling abc
func
Is there any way that func is accessible from the .robot file?
Upvotes: 0
Views: 716
Reputation: 1
Yes, it is possible to call the python function to the robot file.
For example, consider this as your python file as test.py
def add(number1, number2):
sum = number1 + number2
return sum
Now you can import that test.py python file into your robot file.
*** Settings ***
Library test.py
*** Variables ***
${num1} 10
${num1} 20
*** Keywords ***
FunctionCall
${output} add ${num1} ${num2}
Log ${output}
Note: Make sure to keep robot file and python file in the same folder or give the path of python file while importing.
Upvotes: 0
Reputation: 7970
if you use a class in python code, instead of a plain module, your classname should be the same as the filename.
Upvotes: 2