在 Robot Framework 的保存变量中不可能有 ' 吗?
It is not possible to have ' in a saved variable in Robot Framework?
我有这些变量:
*** Variables ***
${current} ""
${doc_type} ""
${document_type} ""
${HoiProo} Hoist\'s Proof Loading Certificate
${HoiMacIns} Hoisting Machinery Inspection Certificate
${inspection_certificate} Certificate.InspectionCertificate
${test_certificate} Certificate.TestCertificate
和这个关键字:
*** Keywords ***
Set Doc_type
${doc_type} = Set Variable If
... '${current}' == '${HoiProo}' ${test_certificate}
... '${current}' == '${HoiMacIns}' ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
整件事
Setup current
${current} ${HoiMacIns}
Setup Doctype
Set Doc_type
但我不明白为什么机器人一直给我这个错误:
Evaluating expression ''Hoisting Machinery Inspection Certificate' == 'Hoist's Proof Loading Certificate'' failed: SyntaxError: invalid syntax (<string>, line 1)
*我也尝试删除'-signs *
Set Doc_type
${doc_type} = Set Variable If
... ${current} == ${HoiProo} ${test_certificate}
... ${current}' == ${HoiMacIns} ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
然后打出来
Set Doc_type
${doc_type} = Set Variable If
... ${current} == Hoist\'s Proof Loading Certificate ${test_certificate}
... ${current}' == ${HoiMacIns} ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
如果 ${current}
是 ${HoiProo}
那么 ${doc_type}
应该是 ${test_certificate}
。这个流程是有效的,因为我已经测试过只比较 ${HoiMacIns}
。将来我想为 if-else 添加更多证书和更多 doc_types
,这就是为什么我需要像这样 运行。
使用表达式时,您必须记住表达式是有效语法在 机器人替换变量之后。如果您的变量包含 Hoist's
并且您尝试使用像 '${HoiProo}'
这样的表达式,机器人将创建像 'Hoist's'
这样的表达式,这是无效的语法。
解决此问题的最简单方法是对表达式中的变量使用特殊语法。如果省略大括号,机器人将直接使用表达式中的变量,无需进行任何额外的引用。
例如:
${doc_type} = Set Variable If
... $current == $HoiProo ${test_certificate}
... $current == $HoiMacIns ${inspection_certificate}
这些都记录在 BuiltIn library documentation in the section named Evaluating expressions 中。
我有这些变量:
*** Variables ***
${current} ""
${doc_type} ""
${document_type} ""
${HoiProo} Hoist\'s Proof Loading Certificate
${HoiMacIns} Hoisting Machinery Inspection Certificate
${inspection_certificate} Certificate.InspectionCertificate
${test_certificate} Certificate.TestCertificate
和这个关键字:
*** Keywords ***
Set Doc_type
${doc_type} = Set Variable If
... '${current}' == '${HoiProo}' ${test_certificate}
... '${current}' == '${HoiMacIns}' ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
整件事
Setup current
${current} ${HoiMacIns}
Setup Doctype
Set Doc_type
但我不明白为什么机器人一直给我这个错误:
Evaluating expression ''Hoisting Machinery Inspection Certificate' == 'Hoist's Proof Loading Certificate'' failed: SyntaxError: invalid syntax (<string>, line 1)
*我也尝试删除'-signs *
Set Doc_type
${doc_type} = Set Variable If
... ${current} == ${HoiProo} ${test_certificate}
... ${current}' == ${HoiMacIns} ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
然后打出来
Set Doc_type
${doc_type} = Set Variable If
... ${current} == Hoist\'s Proof Loading Certificate ${test_certificate}
... ${current}' == ${HoiMacIns} ${inspection_certificate}
Set Suite Variable ${document_type} ${doc_type}
如果 ${current}
是 ${HoiProo}
那么 ${doc_type}
应该是 ${test_certificate}
。这个流程是有效的,因为我已经测试过只比较 ${HoiMacIns}
。将来我想为 if-else 添加更多证书和更多 doc_types
,这就是为什么我需要像这样 运行。
使用表达式时,您必须记住表达式是有效语法在 机器人替换变量之后。如果您的变量包含 Hoist's
并且您尝试使用像 '${HoiProo}'
这样的表达式,机器人将创建像 'Hoist's'
这样的表达式,这是无效的语法。
解决此问题的最简单方法是对表达式中的变量使用特殊语法。如果省略大括号,机器人将直接使用表达式中的变量,无需进行任何额外的引用。
例如:
${doc_type} = Set Variable If
... $current == $HoiProo ${test_certificate}
... $current == $HoiMacIns ${inspection_certificate}
这些都记录在 BuiltIn library documentation in the section named Evaluating expressions 中。