将字典作为参数传递给 RobotFramework 测试 [英] Passing dictionary as argument to RobotFramework test

查看:63
本文介绍了将字典作为参数传递给 RobotFramework 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器人测试中有一本字典,我想从调用该测试的程序中填充该字典.我有两个文件:robotstarter.py 和 printdictionary.robot.但是,当我运行脚本时,测试套件中的字典都是空的.我不确定这是 Python 还是 RobotFramework 相关问题.

I have a dictionary in my robot test that I want to be populated from the program that calls the test. I have two files: robotstarter.py and printdictionary.robot. However when I run the script the dictionary inside the test suite are all empty. I'm not sure whether this is a python or RobotFramework related issue.

robotstarter.py

import robot

test_dict = {'dict.a': '2', 'dict.b': '2', 'dict.c': '2', 'dict.d': '2', 'dict.e': '2', 'dict.f': '2'}
print(test_dict)
robot.run("printdictionary.robot", variable=test_dict)

printdictionary.robot

*** Variables ***
&{dict}    a=${1}    b=${1}    c=${1}    d=${1}    e=${1}    f=${1}

*** Test Cases ***
Test print the identity stuff
    Log To Console     \nDictionary:
    Log To Console     ${dict.a}
    Log To Console     ${dict.b}
    Log To Console     ${dict.c}
    Log To Console     ${dict.d}
    Log To Console     ${dict.e}
    Log To Console     ${dict.f}

推荐答案

它的工作原理是用一个数组替换 robotsstarter.py 中的字典.

It works by replacing the dictionary in robotstarter.py with an array.

test_dict = {'dict.a': '2', 'dict.b': '2', 'dict.c': '2', 'dict.d': '2', 'dict.e': '2', 'dict.f': '2'}

变成:

test_dict = {'dict.a:2', 'dict.b:2', 'dict.c:2', 'dict.d:2', 'dict.e:2', 'dict.f:2'}

这篇关于将字典作为参数传递给 RobotFramework 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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