Inner nested class access from robot framework

后端 未结 2 820
一生所求
一生所求 2021-01-28 19:23

Robot - 3.1.1 Python - 3.7.3

I wanted to access method that are written in nested inner class from robot framework.

Robot:

*** S         


        
相关标签:
2条回答
  • 2021-01-28 19:54

    When Robot Framework imports a library, it tries to import just the class named the same as the .py file - as in your case, the class OrderList in the OrderList.py file. And it doesn't import any other classes - check the documentation for more details.

    The easiest option would be to have the class you are going to use renamed, to the same name as the file.

    If that's not applicable - and looks like your intent is to use more than one class, you could have the file in your PYTHONPATH (like, physically moving the file to a dir in it, or extend it to include the module's one) and import the classes separately as OrderList.Ordertable.
    Another would be to solve it on the python side - put each class in a module of their own, each importing the one with the base class.

    The first is ops nightmare, the second - design & maintenance; your choice :).

    0 讨论(0)
  • Here is an example about how to import a class as a library and not the whole python file:

    1. In a folder named tests there is a test.robot and an OrderList.py file.
    2. OrderList.py:

      class OrderList():
                 pass
      
      class Ordertable(OrderList):
             def click_order(self):
                  print('foo')
      
    3. test.robot:

      *** Settings ***
      Library        OrderList.Ordertable
      
      *** Test Cases ***
      AA
          click order
      
    4. Launch it with the following command from the parent folder of the tests folder: robot --pythonpath .\tests\ --test AA .\tests\test.robot

    5. Result:

      PS prompt> robot --pythonpath .\tests\ --test AA .\tests\test.robot
      ==============================================================================
      Test
      ==============================================================================
      AA                                                                    | PASS |
      ------------------------------------------------------------------------------
      Test                                                                  | PASS |
      1 critical test, 1 passed, 0 failed
      1 test total, 1 passed, 0 failed
      ==============================================================================
      Output:  C:\Users\myuser\output.xml
      Log:     C:\Users\myuser\log.html
      Report:  C:\Users\myuser\report.html
      
    0 讨论(0)
提交回复
热议问题