I have my individual python modules which has many methods to it.
For Example:
ReusableModule.py has
def play_button():
print 'Does play Operation'
def download_music():
print 'Does Download Operation'
I want to use the methods as Keyword in RobotFramework Ride. How to make the methods visible from RIDE?
PS: Edited class name so ROBOT Framework can Identify
When I execute get the following error from Ride: 20130524 01:32:09.254 : FAIL : No keyword with name 'play_button' found.
To import the Python script inside Robot, we use the keyword Library in the Robot file under settings. To call the function, we use <file_name><dot><function name> . To add keywords inside the function, we use the keyword decorator. Here, BuildIn().
Taking resource files into use Resource files are imported using the :setting:`Resource` setting in the Settings section so that the path to the resource file is given as an argument to the setting. The recommended extension for resource files is :file:`. resource`, but also the normal :file:`. robot` extension works.
To import the module, you simply have to put the name of the ROS package where the module was installed, followed by the name of the file. That's it!
The key is in your naming convention - functions and methods in python should be lowercase and the words should be separated by underscores. If you follow that convention, robot framework will pick up these keywords and allow you to use them in your tests, however in the tests the words should be separated by spaces, and are case insensitive. I believe that of you read the documentation there are ways of exposing keywords without following the standard naming convention, but I would urge you top follow convention, especially of anyone else might have to read your code. I would recommend reading PEP-8 as it gives the main style guidelines.
Assuming your have the following ReusableModule.py
:
class ReusableModule(object):
def play_button(self, args):
print "Pressed Play"
You would import like so:
Library ReusableModule
and then run the keyword in your test case as Play Button
As long as ReusableModule.py
is in your path when you run the test you should be fine - this means that it is either in your current directory, or $PYTHONPATH - you can check this by running:
python -c "from ReusableModule import ReusableModule"
from the command line - if this works you should be able to run your test
First of all, to use your module/library in robotframework PYTHONPATH has to contain path to your module. This is no different as is with Python. To make your module known to robotframewotk, make sure you use
Library ReusableModule
in Settings section of Test Suite.
Next, when running tests with pybot on Linux you could do something like this
$ export PYTHONPATH=/directory/contsaining/your/module
$ pybot <options>
With RIDE, you have to modify RIDE settings and also add path to your module. If that is done correctly you should be able to run tests with RIDE and also will have your keywords show up in RIDE completion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With