【发布时间】:2017-08-02 15:18:43
【问题描述】:
我在自动化我的测试用例时遇到问题,所以我的问题是我需要在下一个测试用例中使用输出测试用例值,比如输入...... 我找不到解决方案,有人有想法吗??
【问题讨论】:
标签: testing automation robotframework testcase
我在自动化我的测试用例时遇到问题,所以我的问题是我需要在下一个测试用例中使用输出测试用例值,比如输入...... 我找不到解决方案,有人有想法吗??
【问题讨论】:
标签: testing automation robotframework testcase
Robot Framework guide 在variables 和scope of variables 上有一个特定的部分。在这些部分中,您将找到可以使用的关键字。如果您Set Suite Variable 变量值不应超出套件(即文件)。如果您希望该值超出该点,请使用Set Global Variable。
【讨论】:
如果是单个值,您可以使用“设置套件变量”或“设置全局变量”设置值,并在另一个测试中直接使用相同的值。 (要么) 如果结果以 xml 格式出现,请使用 XML 库并读取值。 示例程序
正如您所提到的,您的输出看起来像<clientID>13044512</clientId> 我正在创建如下所示的 xml 文件:(添加了标签,因为只有它不起作用,它需要一些根标签,让我知道,无论是否出现,如果不是,我将解释如何添加该根标签)
output.xml
<clientID>13044512</clientID>
*** Settings ***
Library XML
Library OperatingSystem
*** variables ***
${xmlFile}= \path\to\xmlfile\output.xml
*** Test cases ***
Access xml tag text
# Get the xml file contents
${file}= Get File ${xmlFile}
#create file and update the old same file with root tag
Create File ${xmlFile} <xml>${file}</xml>
#parse xml to element tree structure and get root tag
${rootTag}= Parse Xml ${xmlFile}
#from root tag find the following element text
${value}= Get Element Text ${rootTag} clientID normalize_whitespace=True
${value} 将具有 13044512 值。
如果xml文件有其他标签,那么在clientID的位置我们需要从根标签指定元素的路径。
希望这能解决问题。
【讨论】: