我使用 Citrix VM,我们有 python 3.7 和机器人 3.1.2。
我有一个自定义关键字的 .robot 文件,用于将页面上元素的值获取到单个变量,然后将该变量设置为全局变量,以便我可以在其他自定义关键字中访问该变量。此 .robot 文件包含页面上许多元素的变量。当我在测试用例中使用此关键字并执行它时,在某些运行中,设置全局变量语句失败并出现错误 - “SyntaxError: invalid syntax (
***Keywords***
Get Field values:
${count}= get element count xpath://<locator1>
${variable1}= run keyword if ${count}>0 get text xpath://<locator1>
convert to string ${variable1}
set global variable ${variable1}
${count}= get element count xpath://<locator2>
${variable2}= run keyword if ${count}>0 get text xpath://<locator2>
convert to string ${variable2}
set global variable ${variable2}
${count}= get element count xpath://<locator3>
${variable3}= run keyword if ${count}>0 get text xpath://<locator3>
convert to string ${variable3}
set global variable ${variable3}
现在,如果在一个测试用例中使用这个关键字并运行它,有时它会通过而没有任何错误,我可以看到变量 1、2 和 3 具有预期的值,我也可以在其他关键字中访问这些变量,因为它们被设置为全局变量. 下次如果我运行,关键字 - set global variable ${variable3} 会失败并出现上述错误,并且相同的语句适用于变量 1 和变量 2。在下一次运行中,相同的语句可能对变量 1 和/或变量 2 失败。请注意,所有这些变量值仅以 $amounts 形式获取值。例如33,600 美元 现在确定为什么它有时会显示“set global variable $”的语法错误,并且错误出现在每次运行的随机字段上。