UI Testing of rulers in source code editors

Q7, 3.05.2013 by Ivan Inozemtsev View Comments

Rulers are important part of modern IDEs, which can display a lot of information, like here:

In this post I am going to illustrate Q7′s built-in support for rulers and describe how to create a couple test cases for various rulers. As an example we are going to use Java editor and a simple “Hello, world!” Java class, like on a screenshot above. A sample Q7 Project with tests is available at Github – https://github.com/xored/q7.examples.rulers

Let’s start with a test case, which checks that if we double-click a ruler, breakpoint will be added and a tooltip will display a method name. To do this:

  1. Start recording
  2. Double-click a ruler on line 9
  3. Move a mouse over breakpoint so that tooltip appears.
  4. Switch to Q7 assertion mode by pressing Alt+Shift+7 hotkey, so that tooltip won’t disappear.
  5. Click on a tooltip, check ‘text’ field in Assertion Window and click “Add”

That’s it, stop recording and save a test case, now Control Panel should display a text like this:

with [get-editor "Program.java" | get-left-ruler] {
    get-ruler-column AnnotationColumn | double-click-ruler -line 9
    hover-ruler -line 9
get-window -from "Information Window" | get-editbox | get-property text 
    | equals "Line breakpoint:Program [line: 9] - main(String[])" 
    | verify-true

In a similar way a test case for asserting folded content can be added – note that in the beginning of a test case we also expanding all folded blocks via context menu in rulers:

with [get-editor "Program.java" | get-left-ruler] {
    get-menu "Folding/Expand All" | click
    get-ruler-column ProjectionRulerColumn | click-ruler -line 5
    get-ruler-column ProjectionRulerColumn | hover-ruler -line 6
get-window -from "SourceViewerInformationControl.()" | get-editbox | 
    get-property text | equals "/**\n"
                             + "\t * @param args\n"
                             + "\t */" | verify-true

A sample Q7 Project with these test cases and a couple more is available at Github – https://github.com/xored/q7.examples.rulers. To run these tests locally without Q7 installation and zero-configuration, simply run these commands in your console (Windows, Linux, Mac OS X):

  $ git clone git://github.com/xored/q7.examples.rulers.git
  $ cd q7.examples.rulers
  $ mvn clean install

There are two bugs now which which might prevent recorded tests from executing, so manual modification might be required in Q7 up to 1.3.2:

  1. QS-2624 – Tooltip diappears too quickly after hover-ruler command. Q7 implementation of hover-ruler is pretty straightforward – based on given line and ruler column it calculates mouse coordinates and sends two mouse events – MouseMove and MouseHover. But for some reason tooltips for some sort of markers (for instance, TODO markers and Error markers) disappear almost immediately, thus a next command asserting a tooltip cannot find floating window. The workaround is simple and works on all platforms, but totally unexpected and so far we have no idea why does it work – but adding a hover-text command on an editor fixes an issue and tooltips stop disappearing:
     with [get-editor "Program.java"] {
         get-text-viewer | hover-text 1 1 // Workaround for QS-2624
         get-left-ruler | get-ruler-column ProjectionRulerColumn | hover-ruler -line 6
  2. QS-2625 – Q7 does not capture ruler column when recording hover-ruler. This issue is trivial and will be fixed in 1.3.2 and has a simple workaround too. Moving a mouse over ruler’s marker records command like get-left-ruler | hover-ruler 4. The fix is to insert missing get-ruler-column between get-ruler and hover-ruler. The simplest way to discover ruler column name is to click on it, but just in case here are the names of ruler columns available:
    • AnnotationColumn – shows breakpoints, TODO items, error markers
    • ProjectionRulerColumn – shows expand/collapse items
    • LineNumberColumn – shows line numbers and/or version control system’s blame annotations

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.