3

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

1

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.