Selecting values in combo

Q7, 11.12.2012 by Ivan Inozemtsev View Comments

When user selects a value from combobox, Q7 records snippet like this:

get-preferences-menu | click
with [get-window Preferences] {
    get-tree | select "Java/Compiler"
    get-group "JDK Compliance" | get-combo -after [get-label 
      "Compiler compliance level:"] | set-text "1.6"
}
Here we record a set-text command to set a value in combobox, and this command works fine independently whether the combobox is readonly or not. However, recently we’ve got an interesting use case from a customer. The application under test has a combobox with values varying on each launch, so line like this is being recorded and cannot be replayed on consequent executions:
get-combo -after [get-label "Value:"] | set-text "Value #123232"
Of course, we filed (and by the time of writing this post already fixed) an issue, but it is an interesting to find a workaround for this issue using current release of Q7. Suppose we want to always select the first value from a combobox. As a reference example we will use a Compiler compliance level combobox in JDT preferences. Let’s start recording, open a preference dialog and switch to assertion mode to get an information about combobox:

Advanced properties of assertion dialog shows all properties of selected widget via reflection, so we can find all items available in given combo. If we check the first item in combobox and click Add, the following line is added to recorded script:
get-window Preferences | get-group "JDK Compliance" | get-combo -after 
   [get-label "Compiler compliance level:"]  | 
   get-property "getItems().String[0]" | 
   equals "1.3" | verify-true
In fact, we don’t need this assertion, but rather we need to get this value and use it as an argument to set-text command. Without extra argument get-property returns a special assertion handle object, which is later being used to build a descriptive error message in case of assertion failure, and in order to extract actual property value, we need to add -raw argument to it. So, going back to the snippet in the beginning of the post and using with command to shorten the script, we can get the following:
get-preferences-menu | click

with [get-window Preferences] {
    get-tree | select "Java/Compiler"

    with [get-group "JDK Compliance" | get-combo -after 
        [get-label "Compiler compliance level:"]] {
        set-text [get-property "getItems().String[0]" -raw]
    }
}
As a result, this script will always select the first value in this combo:

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.