Squish tip of the week: Bring window to foreground

When working with multiple applications, or multiple windows in a single application, you can tell Squish to bring the desired window to the foreground before working with the window.

This applies to many different technologies or toolkits.

For example, when working with NSWindow on Mac OS X (Cocoa), given the name or title of the window, you can do the following:

def main():
    startApplication(...)
    ...

    objName = "{title='MyApp Window #1' type='NSWindow'}"
    waitFor("object.exists(\"%s\")" % objName, 20000)
    nsw = findObject(objName)
    nsw.makeKeyAndOrderFront_(nsw)

Read more about this Mac OS X Cocoa example, or other examples in the following Knowledgebase articles:

Remember; we’re always adding to our knowledgebase and other online resources to provide you with the most current and helpful information!

froglogic_cropped

Squish tip of the week: How to find answers to your Squish questions

There’s a wealth of Squish & Automated GUI Testing information at your finger tips. Sometimes the key is simply knowing where to look!

Visit our Squish Resources page

Squish tip of the week: Automate Business Rule Validation



Applications often have a set of business rules; rules that govern how an application should react based on a given set of input or actions. Or as Wikipedia defines it:

A business rule is a rule that defines or constrains some aspect of business and always resolves to either true or false. Full definition


Validate your application’s business rules using data-driven tests

Take a simple set of steps, perhaps even a Snippet of a Test Case, let’s say lines 7 – 10 in the following example:

def main():
    startApplication("AddressBookSwing.jar")
    activateItem(waitForObjectItem(":Address Book_JMenuBar", "File"))
    activateItem(waitForObjectItem(":File_JMenu", "New..."))
    activateItem(waitForObjectItem(":Address Book - Unnamed_JMenuBar", "Edit"))
    activateItem(waitForObjectItem(":Edit_JMenu", "Add..."))
    type(waitForObject(":Address Book - Add.Forename:_JTextField"), "sam")
    type(waitForObject(":Address Book - Add.Surname:_JTextField"), "smith")
    type(waitForObject(":Address Book - Add.Email:_JTextField"), "sam@smith.com")
    type(waitForObject(":Address Book - Add.Phone:_JTextField"), "123.123.1234")
    clickButton(waitForObject(":Address Book - Add.OK_JButton"))
Ask yourself (or better yet, your team):
  • What are the valid input values in each of these fields?
  • What values are not permitted in each of these fields?
  • Do the fields have any minimum character requirements?
  • Any maximum character requirements?
  • What should display in the event any of these requirements are not met? And when should it display?

Given answers to the above set of questions, you can begin compiling a collection of data to validate the business rules.

Business Rules Data Table
field input result_details comments
1 Forename sam Expected Result: input accepted without error
2 Forename s@m Special characters not permitted in Forename field Expected Result: Warning message appears immediately
3 And so on
Modify your Test Case to use the data

Use the Make Code Data Driven wizard to give yourself a jump start.

click to zoom

Then

  1. Update the text field to use the related variable(s) and
  2. Add a verification point to validate the expected result
Updated example

def main():
    startApplication("AddressBookSwing.jar")
    activateItem(waitForObjectItem(":Address Book_JMenuBar", "File"))
    activateItem(waitForObjectItem(":File_JMenu", "New..."))
    activateItem(waitForObjectItem(":Address Book - Unnamed_JMenuBar", "Edit"))
    activateItem(waitForObjectItem(":Edit_JMenu", "Add..."))
    
    for record in testData.dataset("businessRules.tsv"):
        field = testData.field(record, "field")
        input = testData.field(record, "input")
        result_details = testData.field(record, "result_details")
        comments = testData.field(record, "comments")
        textField = waitForObject(":Address Book - Add.%s:_JTextField" % field)
        textField.setText("")
        type(waitForObject(textField), input)
        waitFor("object.exists(':Address Book - Add.%s_Warning:_JLabel' % field)", 20000)
        test.compare(findObject(":Address Book - Add.%s_Warning:_JLabel" % field).text, result_details, comments)

Squish tip of the week: Reuse tests, scripts and test resources

What makes your test framework shine? Its re-usability of common actions and resources

All scripts, test data, verification points and even gestures in your Test Suite Resources are available to all Test Cases in your Test Suite.

Test Suite

It doesn’t stop there…

With Squish’s real-world scripting language support of Python, JavaScript, Perl, Tcl and Ruby, your scripts, even those independent of Squish, are also available using Squish’s Global Script view.

Global Script View Real-World Examples

Squish tip of the week: Create tests involving multiple AUTs

Squish can create and execute against tests against multiple Applications Under Test (AUT)

Switch between applications (for recording or playback) using Application Context.

Let’s say you are testing a chat application
  • Two chat sessions are interacting.
  • Even if one session is a Desktop application and the other is a Mobile App – it’s all possible!
Learn more here:

froglogic_cropped

Squish tip of the week: Resizing a docked window

Resizing a docked window isn’t always as simple as it may seem.
Docked windows often change height and width as well as their docked location. The control or widget can also be more complex, not resizing with a simple MouseDrag used with non-docked windows.

The example below illustrates how to resize a docked window when working with the Qt Widget QDockWidget:

# About Example
# Supply specific QDockWidget's symbolic or real name
# (in this sample application QDockWidget is ColorSwatch)
# change_* functions take three parameters: QDockWidget
# as o, resize value as xdiff, snooze in seconds
# (optional) as snoozeFactor
 
def main():
    startApplication("mainwindow")
 
    dockToResize = waitForObject(":Qt Main Window Demo.White Dock Widget [*]_ColorSwatch")
 
    change_height_on_top(dockToResize, -20)
    change_height_on_top(dockToResize, 20)
    change_height_on_bottom(dockToResize, -20)
    change_height_on_bottom(dockToResize, 20)
    change_width_on_left(dockToResize, -20)
    change_width_on_left(dockToResize, 20)
    change_width_on_right(dockToResize, 20)
    change_width_on_right(dockToResize, -20)
 
def change_height_on_top(o, xdiff, snoozeFactor = 0):
    snooze(snoozeFactor)
    mousePress(o, 50, -2, MouseButton.LeftButton)
    start = 0
    end = xdiff
    step = 1
    if xdiff < 0:
        step = -1
    for i in range(start, end, step):
        mouseMove(o, 50, -2 + i)
    mouseRelease()
    snooze(snoozeFactor)
 
def change_height_on_bottom(o, xdiff, snoozeFactor = 0):
    snooze(snoozeFactor)
    mousePress(o, 50, o.height + 2, MouseButton.LeftButton)
    start = 0
    end = xdiff
    step = 1
    if xdiff < 0:
        step = -1
    for i in range(start, end, step):
        mouseMove(o, 50, o.height + 2 + i)
    mouseRelease()
    snooze(snoozeFactor)
 
def change_width_on_left(o, xdiff, snoozeFactor = 0):
    snooze(snoozeFactor)
    mousePress(o, -3, 50, MouseButton.LeftButton)
    start = 0
    end = xdiff
    step = 1
    if xdiff < 0:
        step = -1
    for i in range(start, end, step):
        mouseMove(o, -3 + i, 50)
    mouseRelease()
    snooze(snoozeFactor)
 
def change_width_on_right(o, xdiff, snoozeFactor = 0):
    snooze(snoozeFactor)
    mousePress(o, o.width + 3, 50, MouseButton.LeftButton)
    start = 0
    end = xdiff
    step = 1
    if xdiff < 0:
        step = -1
    for i in range(start, end, step):
        mouseMove(o, o.width + 3 + i, 50)
    mouseRelease()
    snooze(snoozeFactor)

For more information, and a more extensive example, see Article – Resizing Docked Windows (QDockWidget)

Squish tip of the week: Using your AUT’s toolkit API

With each Squish edition, or technology supported, you can us the corresponding toolkit’s API from your test scripts.

This gives you access to your application, and to make calls, beyond what can be done from your application’s user interface alone.

Take for example the Java Convenience API

In JavaFx applications you can have more than one top-level window.

How can you ensure the proper top-level window is in front before interacting with it? Use the .toFront() call.

For example, given a symbolic name of MyWindow1, the line would simply read MyWindow1.toFront()

Search doc.froglogic.com for your toolkit’s convenience API, or your the AUT toolkit API documentation.

(Near) endless possibilities!

Squish tip of the week: How to spy menu items using Pick tool

Using the Pick tool to spy items which only appear when a parent or related item is first selected may appear impossible, but it’s not!

Imagine you want to verify or inspect an item in a menu, drop down list, context menu, etc. You click the menu, and then the Pick tool. Clicking away makes the menu close. How can you possibly ‘pick’ such an object?

Two options:
  • Option 1: Select the parent item using the Pick tool and manually navigate the Application Objects tree.
  • Option 2: Run the IDE using a remote connection to where the AUT is running and select the menu item using the Pick tool
Option 2: Remote Squish IDE & the Pick tool

As learned in a prior Squish tip of the week, your Squish IDE can create tests and interact with applications through a remote connection. Read more here: Squish tip of the week: Create tests against a remote environment

  1. Once you have the remote connection setup, record a test (or use Launch AUT) using a Squish IDE on a separate computer from the running AUT (this also works with a host computer and virtual machine).
  2. Click the menu in the AUT to display the menu contents.
  3. Return to the computer where the IDE is running and select the Pick tool.
  4. Because these are two different systems, the menu does not close (or disappear) when you click the Pick tool.
  5. Back on the computer where the AUT is running, select the menu item of interest.
Result:

The Squish IDE now displays the menu item in the Application Objects tree with its associated properties and values in the Properties list.

Squish tip of the week: Insert comments while recording

Want to include notes or comments in your script about what you’re recording?

While recording, the Control Bar contains an Insert Script Comment button
insertScriptComment

  1. Click the Insert Script Comment button
  2. The Comment Window appearsInsertCommentWindow
  3. Enter a comment and click OK

Once you complete your recording, by clicking Stop, the comment appears within your script. The following example’s comment is: # Adding a new entry

def main():
    startApplication("AddressBookSwing.jar")
    activateItem(waitForObjectItem(":Address Book_JMenuBar", "File"))
    activateItem(waitForObjectItem(":File_JMenu", "New..."))
    activateItem(waitForObjectItem(":Address Book - Unnamed_JMenuBar", "Edit"))
    activateItem(waitForObjectItem(":Edit_JMenu", "Add..."))
    # Adding a new entry
    type(waitForObject(":Address Book - Add.Forename:_JTextField"), "sam")
    type(waitForObject(":Address Book - Add.Forename:_JTextField"), "<Tab>")
    type(waitForObject(":Address Book - Add.Surname:_JTextField"), "smith")
    type(waitForObject(":Address Book - Add.Surname:_JTextField"), "<Tab>")
    type(waitForObject(":Address Book - Add.Email:_JTextField"), "sam@smith.com")
    type(waitForObject(":Address Book - Add.Email:_JTextField"), "<Tab>")
    type(waitForObject(":Address Book - Add.Phone:_JTextField"), "123.123.1234")
    clickButton(waitForObject(":Address Book - Add.OK_JButton"))