Question

I am currently toying around with the AutoIt library for Robot Framework, so I'm doing the typical "my first" Robot GUI test and testing the Calculator! Unfortunately my below code generates the error: Dictionary does not contain key 'View Scientific'.. This occurs in the Start Calculator keyword. It seems that whenever I call Select Calculator Menu Item I get an error.

*** 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}

What is the reason for this keyword generating errors?

Thanks in advance.

Was it helpful?

Solution

"Dictionary does not contain key 'View Scientific'" should be pretty self-explanatory. You're trying to use the key "View Scientific" as a key to a dictionary, and that dictionary doesn't have that key.

In your case you have a dictionary named ${MENUMAP} that apparently does not have the key "View Scientific". You need to figure out why your map is missing this key. A simple thing to do is to log the dictionary, which will tell you what keys it has.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top