我目前正在为Robot Framework使用AutoIt库,所以我正在进行典型的“我的第一个”机器人GUI测试并测试计算器!不幸的是,下面的代码生成了错误:Dictionary does not contain key 'View Scientific'.
。这发生在Start Calculator关键字中。似乎每当我调用选择计算器菜单项时,我都会收到一个错误。在
*** Settings ***
| Documentation | Tests AutoIt Library
| Suite Setup | Start Calculator
| Library | AutoItLibrary
| Library | Collections
| Library | String
| Variables | CalculatorGUIMap.py
*** Test Cases ***
| Integer Addition
| | Click Buttons | 2 2 + 2 =
| | Win Wait | Calculator | 24
| | ${Ans}= | Get Answer
| | Should Be Equal As Numbers | ${Ans} | 24
*** Keywords ***
| Start Calculator
| | Run | calc.exe
| | Wait For Active Window | Calculator
| | Get Calculator Version
| | Select Calculator Menu Item | View Scientific
| | Send | 12345
| | ${Result} | ${ErrMsg} = | Run Keyword And Ignore Error | Win Wait
| | ... | Calculator | 12345
| | Run Keyword If | "${Result}"=="FAIL" | Select Calculator Menu Item | View Digit grouping
| | Win Wait | Calculator | 12345
| | Click Button | Clear
| Click Button
| | [Arguments] | ${Button Text}
| | ${ButtonName} = | Get From Dictionary | ${GUIMAP} | ${ButtonText}
| | Control Click | Calculator | ${EMPTY} | ${ButtonName}
| Click Buttons
| | [Arguments] | ${ButtonNames}
| | @{Buttons}= | Split String | ${ButtonNames}
| | :FOR | ${ButtonName} | IN | @{Buttons}
| | | Click Button | ${ButtonName}
| Select Calculator Menu Item
| | [Arguments] | ${MenuItem}
| | ${AltKeys}= | Get From Dictionary | ${MENUMAP} | ${MenuItem}
| | Send | {ALTDOWN}
| | Sleep | 1
| | Send | ${AltKeys}
| | Send | {ALTUP}
| Get Calculator Version
| | Send | {ALTDOWN}
| | Sleep | 1
| | Send | ha
| | Send | {ALTUP}
| | Win Wait Active | About Calculator | Version
| | ${WinText}= | Control Get Text | About Calculator | Version | 13579
| | ${WinText2}= | Run Keyword If | "Version" not in "${WinText}" | Control Get Text
| | ... | About Calculator | Version | Static4
| | ${WinText}= | Set Variable If | "version" in "${WinText2}" | ${WinText2}
| | ... | ${WinText}
| | Run Keyword If | "Version" not in "${WinText}" | Fail | Can't find Calculator version
| | ${GUIMAP}= | Set Variable If | "5.1" in "${WinText}" | ${GUIMAP_51}
| | ${GUIMAP}= | Set Variable If | "6.0" in "${WinText}" | ${GUIMAP_60}
| | ... | ${GUIMAP}
| | ${GUIMAP}= | Set Variable If | "6.1" in "${WinText}" | ${GUIMAP_61}
| | ... | ${GUIMAP}
| | Run Keyword If | ${GUIMAP}== None | Fail | Calculator version not supported: ${WinText}
| | Set Suite Variable | ${GUIMAP}
| | ${MENUMAP}= | Set Variable If | "5.1" in "${WinText}" | ${GUIMAP_51}
| | ${MENUMAP}= | Set Variable If | "6.0" in "${WinText}" | ${GUIMAP_60}
| | ... | ${MENUMAP}
| | ${MENUMAP}= | Set Variable If | "6.1" in "${WinText}" | ${GUIMAP_61}
| | ... | ${MENUMAP}
| | Set Suite Variable | ${MENUMAP}
| | Control Click | About Calculator | Version | Button1
| Get Answer
| | Select Calculator menu Item | Edit Copy
| | ${Answer}= | Clip Get
| | [Return] | ${Answer}
这个关键字产生错误的原因是什么?在
提前谢谢。在
“科学词典”不应包含“科学解释”的观点。您试图使用键
"View Scientific"
作为字典的键,而该字典没有该键。在在您的例子中,有一个名为
${MENUMAP}
的字典,它显然没有键"View Scientific"
。你需要弄清楚为什么你的地图缺少这把钥匙。一件简单的事就是记录字典,它会告诉你它有什么键。在相关问题 更多 >
编程相关推荐