如何从python类调用方法到机械手类

我在python文件中有一个返回值lilke URL的方法.
我想在robot框架中调用它,通过附加environment来启动测试用例.
 下面是我使用的代码.

python和robot文件代码.请让我知道我在哪里做错了.
我正在尝试从python文件调用方法,该方法将url返回到机器人框架类,

Environment.py

class TestUrl:
  def getBaseUrl(self, env):
    if env == 'int':
        domain = 'example.com/'
        return domain


  def getFullUrlForEclaimsHome(self, env, partner):
    x = self.getBaseUrl(env)
    url = 'https://' + partner + x
    print url
    return 'https://' + partner + x

test.robot
*** Settings ***
Variables    ../../CommonTestClass/Environments.py

*** Variables ***
${browser}  chrome
${env}  int
${partner}  example
${example URL}  = call method  getFullUrlForEclaimsHome('${env}','${partner}')


*** Keywords ***
Launch the browser 
    sleep  2s
    Open Browser  ${example URL}  ${browser}
    Maximize Browser Window

解决方法:

文件的名称和类的名称(以我的经验)应该匹配,因此,如果文件名为“ Environments.py”,则您的类应称为“ Environments”,因为一旦在机器人框架中导入它,您将直接调用方法“ getBaseUrl”或“ getFullUrlForEclaimsHome”.

另外,您在类定义中缺少():

class TestUrl():

例:

我的Python文件名为:Tree.py

from anytree import Node, RenderTree

class Tree ():
    def generate_tree (self,db_server,db_table,db_username, db_password):
        DO_SOMETHING

    def retrieve_tree_info (self,db_server,db_table,db_username, db_password, tree_ID):
        DO_SOMETHING
        return (SOMETHING)

我的机器人框架文件:

*** Settings ***
Library           YOUR_LIBRARY
Resource          YOUR_RESOURCE
Library           ../External Library/Tree.py #PATH TO YOUR Tree.py FILE

   #NOTE: If you use some IDLE (I'm using RED) it give you suggestion about the method name, in my example the IDLE call it in a bit different way than it was called in the python file
*** Variables ***
YOUR_VARIABLE

*** Test Cases ***
Create tree
    DO_SOMETHING
    ${tree}=    Retrieve Tree Info    ${db_server}    ${db_name}    ${db_user}    ${db_password}    ${tree_ID}
    DO_SOMETHING

Verify Locations tree
    DO_SOMETHING
    ${tree}=    Retrieve Tree Info    ${db_server}    ${db_name}    ${db_user}    ${db_password}
    DO_SOMETHING
上一篇:1、RF测试环境的搭建


下一篇:RobotFrameWork学习记录--页面下拉框操作之定位确定当前已经选中下拉框的值--2020-02-26