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

时间:2018-08-28 14:50:53

标签: python robotframework

我在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

1 个答案:

答案 0 :(得分:3)

文件名和类名(以我的经验)应该匹配,因此如果文件名为“ 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