5

enter image description hereI 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.

Karthick
  • 675
  • 4
  • 12
  • 24

2 Answers2

5

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.


Further Explanation

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

theheadofabroom
  • 20,639
  • 5
  • 33
  • 65
  • Is it necessary that the methods should be within a class? – Karthick May 23 '13 at 19:34
  • 2
    @Karthick that is optional, however it does give you flexibility in your scoping, and does give you a namespace in which to store any state you might need to persist over the life of the test suite. If you do this you will need to either name the class exactly the same name as the file (I prefer not to do this) or in your import give the full classname, i.e. if you have a class `KlassName` you can place it in a file `KlassName.py` and then from robotframework import `KlassName` or you can place it in `functional_area.py` and import `functional_area.KlassName`. I would recommend the latter. – theheadofabroom May 23 '13 at 20:52
  • Hey thanks for the information. Looks like I have successfully imported the module.. I do not see any import error. But I run, I get "FAIL : No keyword with name 'play button' found" what am I doing wrong? – Karthick May 27 '13 at 18:17
  • 1
    Figured out I got this ImportError: cannot import name splitgophertype any idea how to resolve this? – Karthick May 27 '13 at 18:28
  • @Karthick not really - if you could give a full stack trace or anything I might be able to try - does your library work outside of RF? – theheadofabroom May 28 '13 at 10:25
  • Yeah it does work perfectly outside RF. I have added the screenshot of RF log which has the whole trace. – Karthick May 28 '13 at 17:47
  • Hmm this is a tricky one - it could be soemthing to do with [stackoverflow.com/questions/6086634](http://stackoverflow.com/questions/6086634/import-urllib-or-urllib-2-in-python-2-7-failing-with-importerror-cannot-import) or it could be to do with selenium - you could try `pip install selenium==2.33.0 -U` as I have no issues with that version. Unfortunately there seem to be a lot of results for this error online, and they seem to be caused by various libraries being out of date, so you may have to go through trying to update all of them – theheadofabroom May 29 '13 at 09:39
2

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.

G.Wolf
  • 35
  • 6
  • I tried but got FAIL : No keyword with name 'play_button' found. – Karthick May 23 '13 at 19:35
  • Your keyword would be `Play Button` which would run the python function `play_button` – theheadofabroom May 23 '13 at 21:03
  • Nopes, play_button is just an example which I have used in this post. the actual method is initiate_setup(self,Browser='Firefox') and I see the same error :( 20130527 23:31:43.789 : FAIL : No keyword with name 'initiate setup' found. – Karthick May 27 '13 at 18:17
  • Is your problem solved ? initiate setup should be Initiate Setup with an argument. – binithb Dec 18 '13 at 11:50