我目前正在使用AutoIt的Robot Framework库,所以我正在进行典型的“我的第一次”机器人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}
此关键字产生错误的原因是什么?
提前致谢。
答案 0 :(得分:1)
"字典不包含密钥' View Scientific'"应该是不言自明的。您尝试使用密钥"View Scientific"
作为字典的密钥,而该字典没有该密钥。
在您的情况下,您有一个名为${MENUMAP}
的字典,显然不具有密钥"View Scientific"
。您需要找出地图缺少此键的原因。一件简单的事情就是记录字典,它会告诉你它有哪些键。