Import robot library to Python file and execute keywords in python file

654 views
Skip to first unread message

Rana Dash

unread,
Jul 19, 2018, 3:24:22 PM7/19/18
to robotframework-users
Hi
  My requirement is to import robot library to python file and execute the robot keywords as python functions in python file. i have gone through lots of documents and in everywhere all are giving the solution which is not working. I am new to robot framework i don't have any idea is it possible or not. Is anyone who had done this task before, can help me?

from robot.libraries.BuiltIn import BuiltIn

def call_keyword(keyword):
    return BuiltIn().run_keyword(keyword)

Bryan Oakley

unread,
Jul 19, 2018, 4:03:30 PM7/19/18
to rana.d...@gmail.com, robotframework-users
This is exactly how you do it. Though, you'll probably want to support the ability to pass additional arguments. Why do you think it's not working? Are you getting an error?

For example, put the following in a file named "mykeywords.py":

from robot.libraries.BuiltIn import BuiltIn

def call_keyword(keyword, *args, **kwargs):
    return BuiltIn().run_keyword(keyword, *args, **kwargs)
In the same folder, create a robot file that looks like this:
*** Settings ***
Library  mykeywords.py

*** Test Cases ***
Example
    call keyword  log to console   hello, world

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages