Import Robot框架:资源的条件导入
是否可以在robot框架中有条件地导入资源文件?根据测试环境的不同,我希望导入具有不同变量的资源文件。可以从robot CLI读取变量(例如robot--变量VAR:production myTestSuite) 举例说明:Import Robot框架:资源的条件导入,import,frameworks,robotframework,Import,Frameworks,Robotframework,是否可以在robot框架中有条件地导入资源文件?根据测试环境的不同,我希望导入具有不同变量的资源文件。可以从robot CLI读取变量(例如robot--变量VAR:production myTestSuite) 举例说明: *** Settings*** Resource variables_url_environment_a.robot Resource variables_url_environment_b.robot Run keyword if '${VAR}'=
*** Settings***
Resource variables_url_environment_a.robot
Resource variables_url_environment_b.robot
Run keyword if '${VAR}'=='production' Import resource variables_url_environment_b.robot
您可以使用具有不同环境变量的参数文件,您可以使用 QA.args
--variable Enviroment:http://sample.url/QA:1111
--variable USER:John
--variable PASSWORD:John
然后在你的机器人测试中
*** Test Cases ***
Run Argument File
Go To ${Enviroment}
Login With User ${USER} ${PASSWORD}
注意:这只是参数文件use Login with User不是实际关键字的一个示例
然后执行命令
robot --argumentfile "QA.args" tests
您还可以覆盖命令行上的变量
robot --argumentfile "QA.args" --variable Enviroment:http://sample.url/Staging:1111 tests
可以在导入文件的名称中使用变量。 在使用maven的情况下,从pom.xml文件中设置变量的值 如下所示,${PLATFORM}是一个变量:
*Settings*
Resource ../platforms/settings_${PLATFORM}.tsv
Resource ../platforms/settings_default.tsv
*Variables*
${PLATFORM} ${ENV_PLATFORM}
下面是POM.xml中的代码片段
....
<env.platform>Platform1.</env.platform>
....
<configuration>
<variables>
<param>ENV_PLATFORM:${env.platform}</param>
</variables>
</configuration>
....
。。。。
平台1。
....
环境平台:${ENV.PLATFORM}
....
此外,通过这种方式,您可以从jenkins处传递平台的值(如果使用)
使用-Denv.platform=platform_5我认为机器人框架中的条件imort不可能以您喜欢的方式实现。 但是,您可以做的不是将envorimnent文件作为resources导入,而是将它们作为--variablefile 我将如何做? 变量\u url\u环境\u a.py
msg='env a'
msg='env b'
变量\u url\u环境\u b.py
msg='env a'
msg='env b'
测试机器人
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
现在,只需创建一个简单的python脚本,根据需要的环境运行测试套件
Python运行脚本
*** Settings ***
*** Variables ***
*** Test Cases ***
print message to console
print msg
*** Keywords ***
print msg
log to console ${msg}
import subprocess
var='Production'
command_a='pybot -V variables_url_environment_a.py Test.robot'
command_b='pybot -V variables_url_environment_a.py Test.robot'
if var='Production':
procId = subprocess.Popen(command_a,stdout = subprocess.PIPE)
else:
procId = subprocess.Popen(command_b,stdout = subprocess.PIPE)
有关如何使用--variablefile的更多信息,还可以参考下面的url
如果“${VAR}”==“iOS”导入库a.py,则运行关键字