0
我是Robot framework自动化测试的新手。我为使用Python的简单Quiz应用程序编写脚本和库,并遵循关键字驱动的方法来测试用例。 我的脚本是:在Robot Framework中使用关键字驱动方法执行测试用例时出现错误
class Quiz(object):
OPTIONS = 'ab'
count = 0
def __init__(self):
self._score = 0
Quiz.count+=1
def score(self, str1):
if str1 not in self.OPTIONS:
raise QuizError("Invalid button '%s'." % str1)
if str1 == 'a' and Quiz.count == 1:
self._score +=1
elif str1 == 'a' and Quiz.count == 2:
self._score +=1
elif str1 == 'a' and Quiz.count == 3:
self._score +=1
return self._score
class QuizError(Exception):
pass
库文件:
from quiz import Quiz, QuizError
class QuizLibrary(object):
def __init__(self):
self._calc = Quiz()
self._result = 0
def option(self, answer):
self._result = self._calc.score(answer)
def result(self, expected):
if self._result != expected:
raise AssertionError('%s != %s' % (self._result, expected))
keyword_driven.txt:
*** Settings ***
Library quizlibrary.py
*** Test Cases ***
Quiz Answer
option a
option b
option a
result 2
它显示了以下错误:
Quiz Answer FAIL |
No keyword with name 'option' found.
----------------------------------------------------------------------------------------
Testcase :: Example test cases using the keyword-driven testing approach. | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
任何人都可以帮助我至 解决这个?
请让我知道如何在关键字驱动的方法中创建用户关键字。
模块的名称没有问题,但它始终显示“关键字未找到”。您能告诉我为什么会显示此错误吗? – Nithya 2015-02-25 06:29:12
我在本地复制了您的代码(使用我建议的修复方法),并且可以使其正常工作...因此,如果您仍然有“未找到关键字”,这意味着库文件没有正确加载。在日志中,你有没有关于lib的加载的错误信息? – 2015-02-25 09:12:51
你..问题与您的建议解决。感谢您的答复 – Nithya 2015-02-26 12:09:17