Asserting context menus

Q7, 13.12.2012 by Ivan Inozemtsev View Comments

During test case recording Q7 assertion mode allows to select a UI element in application under test and generate assertion lines in a script for selected properties. For instance, to check that “Save” button on Eclipse toolbar is disabled, we can switch to recording mode, select a button, check “enablement” property and click “Add”:

As a result, the following line will be appended to the script:

get-button "Save (M1+S)" | get-property enablement | equals false |

And in case this button is enabled during replay, test case will fail with a message: Assertion of enablement failed: expected:<false> but was:<true>

Yesterday one of our customers asked how to assert properties of context menus, as there’s a problem – once user switches to assertion mode, he cannot invoke context menu, as all user operations are blocked. And if context menu is open and then user goes to Control panel, context menu looses focus and closes. So, what can we do here to assert them?

The solution is to manually write ECL commands to perform these assertions. As an example, suppose we need to assert the following statements about context menu of a Java project in Package explorer:

  1. The menu item New has children
  2. The menu item Close Project is enabled
  3. The menu item Compare With / Each Other is disabled
  4. The menu item Open Project does not exist

At first, let’s take a look at what is being recorded when we click on some item in context menu:

get-view "Package Explorer" | get-tree |
 select sample | get-menu "New/Class" | click

So the sctipt takes a package explorer, finds a tree in it, selects an item “sample”, gets context menu item “New -> Class” and clicks on it. Comparing this script with an assertion example above, We can replace a click with a series of commands for assertion like this:

get-view "Package Explorer" | get-tree | select sample | 
 get-menu "New/Class" | get-property enablement | equals true |

Here is a list of properties on menu items which can be used for assertion:

  • enablement – whether an item is enabled
  • accelerator – assigned hotkey
  • cascade – whether an item has children
  • caption – menu item text

Given that, it is easy to implement three first assertions, but how to make sure that an item does not exist? This can be done by using verify-error command, which accepts a script as a parameter and passes if script fails, and fails otherwise. Therefore, we can write the following script:

with [get-view "Package Explorer" | get-tree | select sample] {
    get-menu "New" | get-property cascade | equals true | verify-true
    get-menu "Close Project" | get-property enablement | equals true |
    get-menu "Compare With/Each Other" | get-property enablement | 
       equals false | verify-true
    verify-error {
        get-menu "Open Project"

blog comments powered by Disqus

Functional and UI Testing for Eclipse-based Applications

Test automation solution, handcrafted for Eclipse. Modern and easy to learn IDE.

Product Health Analytics and Support Automation Platform

End-user and product analytics solution that gives you rich insights into your application health & performance.

Eclipse-based IDE for the Fantom Programming Language

Full-featured Integrated Development Environment for emerging Fantom programming language.