我需要使用另一个变量通过命令行更改 Robot 变量
I need to change a Robot variable by command line using another variable
所以我研究了很多,所以我想也许我正在考虑一个简单问题的复杂解决方案。
我在 Robot 中有一个测试,它使用 python 字典中的一个变量。
机器人文件:
*** Settings ***
Variables Data.py
*** Variables ***
${check}= TEST.abc
*** Test Cases ***
Test
Do the test ${check}
python字典:
DICT__TEST = {"abc": "123", "def":"456"}
在上面的这种情况下,例如,我想在命令行中将变量 "def"
作为参数传递,以替换变量 ${check}
。
我看到有 --variable
但它只是通过字符串而不是另一个变量更改机器人的变量。
这本词典已经可以在 Robot 上正常使用了,因为我没有太多经验,所以我可能会想出一种非常困难的方法来解决一些简单的问题。我接受其他建议,但基本上我有一个非常大的字符串,我需要通过命令行传递它来更改 Robot 中的变量。
如果我没理解错的话,你的字典中有键值对,你想将值保存到变量中。并且您想从命令行提供密钥。
您可以 运行 robot -v dictkey:def mytest.robot
并且它将使用变量
*** Settings ***
Library Collections
Suite Setup SetDict
*** Variables ***
${dictkey} abc
*** Keywords ***
SetDict
${sample_dict}= Create Dictionary abc 123 def 456
Set Suite Variable ${sample_dict}
*** Test Cases ***
Test
${value}= Get From Dictionary ${sample_dict} ${dictkey}
Log To Console ${value}
所以我研究了很多,所以我想也许我正在考虑一个简单问题的复杂解决方案。 我在 Robot 中有一个测试,它使用 python 字典中的一个变量。
机器人文件:
*** Settings ***
Variables Data.py
*** Variables ***
${check}= TEST.abc
*** Test Cases ***
Test
Do the test ${check}
python字典:
DICT__TEST = {"abc": "123", "def":"456"}
在上面的这种情况下,例如,我想在命令行中将变量 "def"
作为参数传递,以替换变量 ${check}
。
我看到有 --variable
但它只是通过字符串而不是另一个变量更改机器人的变量。
这本词典已经可以在 Robot 上正常使用了,因为我没有太多经验,所以我可能会想出一种非常困难的方法来解决一些简单的问题。我接受其他建议,但基本上我有一个非常大的字符串,我需要通过命令行传递它来更改 Robot 中的变量。
如果我没理解错的话,你的字典中有键值对,你想将值保存到变量中。并且您想从命令行提供密钥。
您可以 运行 robot -v dictkey:def mytest.robot
并且它将使用变量
*** Settings ***
Library Collections
Suite Setup SetDict
*** Variables ***
${dictkey} abc
*** Keywords ***
SetDict
${sample_dict}= Create Dictionary abc 123 def 456
Set Suite Variable ${sample_dict}
*** Test Cases ***
Test
${value}= Get From Dictionary ${sample_dict} ${dictkey}
Log To Console ${value}