在机器人框架工作中,我们如何使用从一个关键字返回的值直接作为另一个关键字的输入参数(不使用变量) [英] In Robot Frame Work How Can we use value returned from one keyword as input argument to other keyword directly(without use of variable)

查看:55
本文介绍了在机器人框架工作中,我们如何使用从一个关键字返回的值直接作为另一个关键字的输入参数(不使用变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个关键字返回的值直接作为另一个关键字的输入参数(不给变量赋值)

How Can we use value returned from one keyword as input argument to other keyword directly (without assigning return value to variable)

目前我在 Excel 工作表中维护所有 Web 元素或变量名称以及相应的 xpath.我通过将 web 元素/变量名称作为参数传递使用关键字 read_xpath 来获取 XPath.

Currently I am maintaining all Web Elements or Variable names and corresponding xpath in an Excel Sheet. I get XPath using keyword read_xpath by passing web element/variable name as argument.

我将 xpath 存储在单独的变量中,然后将它用于其他或下一行关键字.由于我需要为每个 XPath 访问使用一个变量,我试图找出是否有任何方法可以直接使用一个关键字输出作为另一个关键字的输入而不将其分配给变量.

I store the xpath in separate variable then make use of it for other or Next line keyword. Since I need to use a variable for each XPath access, i am trying to find out, whether is there any way to directly use one keyword output as input to other keyword without assigning it to variable.

将 XPath 存储在 Excel 工作表中的主要目的是为了避免单个元素 XPath 更改导致多个测试用例更改,只需在 Excel 工作表上进行一次更改就足够了.

The main purpose of storing XPath in Excel sheet is to avoid multiple test cases change with single Element XPath change, making just single change on Excel Sheet should be sufficient.

例如:read_xpath 从 Excel 表中读取值,Excel 表有两列,一列 变量名,第二列是 xpath.函数read_xpath(element)变量名作为输入并返回xpath.

For Example: read_xpath reads values from a Excel sheet, Excel sheet has two columns, one variable name and second one is xpath. Function read_xpath(element) takes variable name as input and gives back xpath.

xlread.py 文件看起来像 xlread.py 代码 Excel Sheet 看起来像 Excel 表格

xlread.py file looks like xlread.py code Excel Sheet look like Excel sheet

sample.robot 文件如下所示

${login_user_textctrl}=  read_xpath    username_textctrl

clear element text  ${login_user_textctrl}
Input text    ${login_user_textctrl}    admin

现在让我们检查一下我如何在我的机器人文件中使用 read_xpath 关键字

Now let us check how I used read_xpath keyword in my robot file

我用参数 username_texctrl 调用了 Keyword read_xpath,它返回存储在变量 ${login_user_textctrl} 中的用户名文本 Control 的 xpath.现在输入文本 ${login_user_textctrl} 管理员工作正常.

I called Keyword read_xpath with argument username_texctrl, which returns xpath for username text Control which is stored in variable ${login_user_textctrl}. Now Input Text ${login_user_textctrl} admin works fine.

对于下面的代码

      clear element text    read_xpath     username_textctrl           

我明白了,清晰的元素文本需要 1 个参数,但提供了两个参数,有什么方法可以将 Keyword(read_xpath) 返回的值直接用作其他关键字的输入,而不将其分配给任何变量?

I am getting, clear element text requires 1 argument but two arguments provided, is there any way i can use the the value returned from Keyword(read_xpath) as input to other keyword directly, without assigning it to any variable?

提前致谢.

推荐答案

您可以使用 Evaluate 直接调用 python 函数.示例:

You can use Evaluate to call python functions directly. Example:

${my element to clear}=    Evaluate    read_xpath("username_textctrl")    xlread  

查看文档此处

(注意:示例未经测试,您应该检查 xlread 是否在 PYTHONPATH 中,或在测试运行时找到)

(Note: Example is untested and you should check if xlread is in PYTHONPATH, or found at test run time)

这篇关于在机器人框架工作中,我们如何使用从一个关键字返回的值直接作为另一个关键字的输入参数(不使用变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆