robotframework调用python类方法_如何从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

标签:robotframework,python

来源: https://codeday.me/bug/20191108/2009170.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值