0

Python version: 3.7.8 Robot framework: 3.1.2

I have a python class where specified a class variable to store and retrieve data later in robot framework.

Example: class1

class test1():
   __testvar__=[]

   def set_data(self, data):
      test1.__testvar__.append(data)

   def get_data(self)
      return test1._testvar__

   def main_calling_method(self):
      ...something...
      self.set_data(data)

class2:

from ...test1 import test1
class test2():
   t=test1()

   def get_method_data(self)
      return test2.t.main_calling_method()

Robot framework: Robot1 File :

*** Settings ***
Library   Pathto\test2.py

*** Keywords ***

 callingkeyword
 ${body}=  get_method_data
 [RETURN]  ${body}

 main keyworkd
 ${response}=  callingkeyword
 [RETURN]  ${response}

Robot2 File:

*** Settings ***
Resoure Pathto\Robot1.robot
Library Pathto\test1.py

*** Keywords ***
testing
${temp}=  main keyworkd
${data}=  get_data
log to console  ${data}

Expected Results:- Value of class variable --testvar__ to be printed in console

Actual Results:- Prints empty list.

If I run the method 'get_data' from python, it prints the data that are added as part of set_data but not producing the same results while running from robot framework.

However, if I call set method like below, before calling get_method, then prints the data properly.

  *** Keywords ***
    testing
    ${temp}=  main keyworkd
    set_data=  testing
    ${data}=  get_data
    log to console  ${data}

Could you please assist where the issue is?

Note: The above scenarios are dummy code for understanding purpose only as I can't share the actual project codes due to security concerns.

4
  • 1
    There's a lot to explain. You seem to have an obfuscated understanding of classes, instances, namespaces, etc. I suggest to study them on a book Commented Dec 30, 2019 at 17:53
  • Any hint would help Commented Dec 30, 2019 at 18:25
  • Your indentation and some robot syntax is broken. If we copy and paste your code exactly, robot throws errors. Also, it would make it easier for us to understand your code if you used PEP8 naming conventions. It's confusing to see class names that start with a lowercase letter. Plus, nowhere do you provide any testcases which call these keywords. Commented Jan 17, 2020 at 16:36
  • We need a proper minimal reproducible example that actually reproduces the problem you're seeing. When I fix all of the obvious (to me) mistakes, your code works as intended - whatever I put in data inside of main_calling_method appears on the console. Commented Jan 17, 2020 at 16:45

1 Answer 1

0

Seems like you didn't put any data into the class, so you didn't get any output when printing. But in the second part code you showed, where you called "set_data= testing" (I suppose this 'testing' is another keyword you customed?), seems like it put the data into the class, so you can print it out.

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.