gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:46:04 25 4
gpt4 key购买 nike

我目前正在使用机器人框架进行一个具有 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}

我想将关键字“Give 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}

Python 库:

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 个空格(更好的可读性)。

关于python - 在机器人框架中定义包含变量的关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53297025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com