繁体   English   中英

在机器人框架内定义包含变量的关键字

[英]Define a keyword containing a variable within robot framework

我目前正在将机器人框架用于具有 Gherkin 语言策略(Given When Then)的项目。

我的特征文件如下:

*** 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}

我想将关键字“ Given the king is ${hungriness}” 链接到 Python 模块 Eat_or_pass.py 中包含的 Python 定义,该模块当前实现如下:

class Eat_or_pass(object):

def given_the_king_is_hungriness(self):
    pass

当我运行机器人框架时,出现以下错误:“致命甜点 | 失败 | 未找到名称为 'Given the king is ${hungriness}' 的关键字。” 我不知道如何解决它。 有没有人可以帮助我解决这个问题?

机器人代码:

*** 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}

蟒蛇库:

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

我建议你对 python 使用 CamelCase,对 RF 使用 4 个空格(更好的可读性)。

*** Keywords ***
The result of ${hungriness} should be ${dessert}
    Given The king Is Hungriness   

它应该被赋予国王是饥饿的而不是被赋予的国王是 ${饥饿}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM