1

I'm currently using robot framework for a project with Gherkin language strategy (Given When Then).

My feature file is as below:

*** Settings ***
Documentation
... In Order to eat a dessert safely, 
... As a king
... I want to not take a lethal dessert 

Library eat_or_pass.Eat_or_pass


*** Test cases ***
Lethal Dessert
    [Template]  The result of ${hungriness} should be ${dessert}
    very hungry apple pie   
    hungry      biscuit
    not very hungry apple


*** Keywords ***
The result of ${hungriness} should be ${dessert}
    Given the king is ${hungriness}
    Then the related dessert is ${dessert}

I would like to link the keyword " Given the king is ${hungriness}" to its python definition contained in the python module Eat_or_pass.py which is currently implemented as below:

class Eat_or_pass(object):

def given_the_king_is_hungriness(self):
    pass

When I run robot framework, I have this error : "Lethal Dessert | FAIL | No keyword with name 'Given the king is ${hungriness}' found." And I don't know how to solve it. Does anyone can help me on the subject?

2 Answers2

2

Robot code:

*** Settings ***
Documentation
...    In Order to eat a dessert safely,
...    As a king
...    I want to not take a lethal dessert
Library    ./EatOrPass.py

*** Test Cases ***
Lethal Dessert
    [Template]    The Result Of ${hungriness} Should Be ${dessert}
    very hungry    apple pie
    hungry    biscuit
    not very hungry    apple

*** Keywords ***
The Result Of ${hungriness} Should Be ${dessert}
    Given The King Is ${hungriness}
    Then The Related Dessert Is ${dessert}

python lib:

from robot.api.deco import keyword


class EatOrPass(object):

    @keyword('The King Is ${hungriness}')
    def the_king_is(self, hungriness):
        pass

    @keyword('The Related Dessert Is ${dessert}')
    def the_related_dessert_is(self, dessert):
        pass

I suggest you to use CamelCase for python and to use 4 spaces for RF (better readability).

Jan Kovařík
  • 1,542
  • 1
  • 11
  • 18
  • It is probably working but I don't have the robot.api.deco installed on my laptop and I am not allowed to install it. Do you have another solution? – TataSetelem Nov 15 '18 at 09:01
  • You can always do it without embedded arguments. In such case the decorator isn't needed and you just define and use your keywords with normal argument(s). Is it OK for you? Can you manage it by yourself? – Jan Kovařík Nov 15 '18 at 12:11
  • Of course I can but it means that I have to multiply the number of test cases ! I can handle it, anyway thank you very much for your help – TataSetelem Nov 15 '18 at 13:32
  • I don't think so. Your python-defined keywords would be without embedded arguments, but the one robot-defined keyword can stay as it is. All the suggested robot code could be like it is in answer except you would call your python-based keywords like `Given The King Is${hungriness}`. – Jan Kovařík Nov 15 '18 at 14:33
  • I used the code source of robot.api.deco public library, I implemented exactly on this way but the keywords are still not found. Do you have another solution? – TataSetelem Nov 28 '18 at 14:48
  • Did you take this into account? http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-library-names In the above example the file with python code was EatOrPass.py – Jan Kovařík Nov 28 '18 at 18:21
  • All my implementations are based on the Robot framework User guide so I did yes – TataSetelem Nov 29 '18 at 09:35
-2
*** Keywords ***
The result of ${hungriness} should be ${dessert}
    Given The king Is Hungriness   

It Should be Given The king Is Hungriness not Given the king is ${hungriness}

class Eat_or_pass(object):
  def given_the_king_is_hungriness(self):
  pass