5

I have a python file for example Animals.py, inside I defined 3 different classes like that:

#Animals.py
class Animal:
    listAnimal=["dog","cat"] #<------------
    def __init__(self):
        #Animal constructor
        pass

class Dog(Animal):
    def __ini__(self):
        #dog constructor
        pass
class Cat(Animal):
    def __ini__(self):
        #cat constructor
        pass

I would like to get access to the class variable listAnimal

I am not an expert of RF I tried to use that:

Import Library   Animal
${ListAnimal}   Animal.listAnimal

could you give some suggestion on that please?

0

2 Answers 2

8

You can use the Get Library Instance keyword from the BuiltIn library to get the currently active instance of the specified test library. Then you can use the Extended variable syntax to access the list and its elements.

Example:

${lib}=     Get Library Instance    Animal
Log     ${lib.listAnimal[0]}    # should log 'dog'
Log     ${lib.listAnimal[1]}    # should log 'cat'
${ListAnimal}=    Set Variable   ${lib.listAnimal}
0
4

I added a new function to the file Animals.py

def getListAnimals():
    return Animal.listAnimal

And I am now only using this function in the robot framework:

Import Library   Animals.py
${ListAnimal}   Get List Animals

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.