Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the object variable in Robot Framework?

My defined class in Python:

class jpg(Abc):
    def __init__(self, *args, **kwargs):
        super(jpg, self).__init__(**kwargs)
        self.TAG = 'tag'
        self.PARAMS = {}

I import this class in Robot framework:

Import Library  jpg    host=${ip}   WITH NAME   jpg

How can I call PARAMS in Robot Framework? I tried with ${jpg.PARAMS} or jpg.${PARAMS}, but it didn't work

I want to do 2 actions on this variable: set and get

like image 606
user3822709 Avatar asked Feb 01 '26 01:02

user3822709


1 Answers

You can create a new python keyword to use the class.
It may like this:

class_test.py

class jpg(object):
    def __init__(self, *args, **kwargs):
        self.TAG = 'hello tag'
        self.args = args
        self.PARAMS = {}


def test_jpg(*args, **kwargs):
    return jpg(*args, **kwargs)

Then, you can use it in your robot files like this:

test.robot

*** Settings ***
Library         class_test.py


*** Test Cases ***
python class test
    [Tags]    class
    [Documentation]    python class test
    ${ret}=    test_jpg    class_tag
    Log    ${ret.TAG}
    Log    ${ret.args}

log file like below: log_file

like image 146
caimaoy Avatar answered Feb 04 '26 01:02

caimaoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!