0
votes

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.

1

1 Answers

1
votes

There must be a problem with the name of the Python module used for your keyword library.

  • if the name of your module is QuizLibrary.py, then change the case in the Library import in your test:

Library QuizLibrary.py

  • if the name of your module is quizlibrary.py, then align the name of the class with this:

class quizlibrary(object):

And also, don't forget to have at least 2 spaces between "Library" and the name of the library.