I am new to Robot framework automation testing.I wrote script and library for simple Quiz application using Python and follows keyword driven approach for test cases. my script is:
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
library file:
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
It shows the following error:
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
could anyone help me to solve this?
Please let me know how to create user keywords in keyword driven approach.