Squish tip of the week: Handling mouse position sensitive drag and drops

Mouse cursor position can impact some drag and drop objects in applications.

In a recent application I was working with, drag and dropping objects to new locations worked with the build-in drag and drop functionality; however connecting those objects with a workflow style arrow, required the mouse cursor to first hover over a specific quadrant of the object before the line drawing could take place using a drag and drop command.

To address this, I created a slightly altered drag and drop function called dragAndDropConnection. While the example below applies to a Java application, the same theory, or approach is applicable to other application toolkits.

function dragAndDropConnection(canvasObj, sx, sy, dx, dy){
    mouseMove(waitForObject(canvasObj), sx, sy);
    snooze(2);
    dragAndDrop(waitForObject(canvasObj), sx, sy, 
        canvasObj, dx, dy, DnD.DropNone);
}

The mouseMove line is the key to this case. The snooze(2), while not required, helped me to witness the breakdown of the dragAndDropConnection function.

Keep in mind, the coordinates are relative coordinates, relative to the object on which the action in performed, in this case, the canvas.

To further optimize connecting the drag and dropped objects, one could calculate the relative location from which to draw the connection based on the original drag and drop location of the two objects on the canvas.

The arrow you wish to move the cursor to resides on the left edge of the object, and about half-way between the top and the center (vertically). Given that you can use:

mouseMove(waitForObject(canvasObj), sourceElementX * 0.9,
    sourceElementY * 0.8);

(more…)

Squish tip of the week: How to execute keyboard and mouse combination commands

How can I perform a keyboard + mouse combination in a test script?

The mouseClick function accepts a modifierState and a button. The modifier state accepts a set of keyboard commands.
Take for example performing a Control + Shift + Right Click

Given a Java Swing application, Shift is 1 and Control is 2
Which results in mouseClick(“:myObject”, 5, 5, 1|2, Button.Button3), where the Shift + Control keys are pressed, followed by Button3, or a right click.

Each application type may use different modifier values:

Java Applications

Squish tip of the week: Use data to validate endless scenarios

You’ve most likely heard of data-driven tests. A key term often used in Automated GUI Testing.

But did you realize the power a set of data can provide within a single test case?

Take a simple example of enrolling a user in a membership-based program. Within the few registration fields, many variables exist:

  • What are all valid characters in each given field?
  • What are the invalid characters in each given field?
  • Minimum number of characters
  • Maximum number of characters
  • Must the field contain specific characters, such as an @ symbol?
  • Is each given field required? Or under what circumstances is each given field required?
  • etc.

Using a single iterating test case, a set of input data, as well as the anticipated result, you can validate a large set of business rules, or features/requirements.
Now imagine validating each of these scenarios manually…

Think of an area in your application where your testing could greatly benefit from such a scenario. Incorporate the test, among others, in your build process, and measure the testing duration savings!

Squish tip of the week: How to determine if a checkbox is checked?

You can check the state of a checkbox, radio button, or the property of any other object or widget using Squish.

Using a test.compare() Verification Point

The line below looks at the object :Controls.My_CheckBox and indicates if the verification point passed or failed: passed if the checkbox is checked, and failed if the checkbox isn’t checked:

test.compare(findObject(":Controls.My_CheckBox").checked, True)

(more…)

Squish tip of the week: Enable Verbose Test Result Logging

Need more detailed information in your test results?

Nightly or scheduled test runs results often provide valuable quick-read information.

What about times when verbose logging, or a Test Audit Log, may prove valuable?

The following example illustrates how to create a fully-customizable Test Audit Log using Squish. Each action is modified to include a log message and description when executed. Simply calling the enableVerboseLogging() function from the main() test case activates verbose logging.

Functionality available for all Squish-supported scripting languages and application toolkits. Example in Python using Java Swing application.

source(findFile("scripts","logScriptActions.py"))

def main():
    startApplication("AddressBookSwing.jar")
    enableVerboseLogging()
    ...
# activate item
def alterActivateItem(activateItemFunction):      
    def wrappedFunction(menuObject, 
                       logText="activateItem() called"):
       test.log(logText, 'Activated item %s' % objectMap.
                symbolicName(menuObject))
       activateItemFunction(menuObject)
    return wrappedFunction

# click button   
def alterClickButton(clickButtonFunction):       
    def wrappedFunction(button, logText="clickButton()"
                        + " called"):    
        test.log(logText, 'Clicked %s' % objectMap.
                 symbolicName(button))
        clickButtonFunction(button)
    return wrappedFunction
    
# mouse click 
def alterMouseClick(mouseClickFunction):   
    def wrappedFunction(objectToClick, posX=None, 
                   posY=None, buttonClicks=None, 
                   buttonState=None, buttonPressed=None,
                   logText="mouseClick() called"): 
        test.log(logText,'Mouse clicked %s' % objectMap.
                 symbolicName(objectToClick))
        mouseClickFunction(objectToClick)
    return wrappedFunction

# type
def alterTypeFunction(typeFunction):
    def wrappedFunction(objectToTypeIn, stringInput,
                        logText="type() called"):
        test.log(logText, 'Typed %(text)s in %(field)s'
                 % {"text":stringInput, 
                    "field":str(objectMap.
                        symbolicName(objectToTypeIn))})
        typeFunction(objectToTypeIn, stringInput)
    return wrappedFunction

# call Squish function modifications
def enableVerboseLogging():
    test.log("Verbose logging enabled")
    
    global activateItem
    activateItem = alterActivateItem(activateItem)
    
    global clickButton
    clickButton = alterClickButton(clickButton)
    
    global mouseClick
    mouseClick = alterMouseClick(mouseClick)
    
    global type
    type = alterTypeFunction(type)

(more…)

Yet another static code analyzer run

Looking for the answer to a 64-bit build question I ran into a news item titled “The Unicorn Getting Interested in KDE“. Since I never saw an unicorn before this made me curious.

Turns out that a company selling a static code analysis tool has been analysing KDE code. This is not the first time some provides such feedback to Open Source projects. Did this

My favourite finding is this redundant if() statement:

if ( type == "String" ) t += defaultValue; //<==
else t+= defaultValue; //<==

Can anyone tell how old the KDE code base is? And did they approach anyone from the project, yet? The posting is just two days old but it might already be old news in todays age...

Measuring QML Coverage

Last year we started receiving the first requests for QML coverage. “Sure. We’ll look into it.”, we replied. It seemed like a logical extension of our cross-language coverage tool Squish Coco. At least on first sight.

At this year’s Qt Contributors’ Summit the question came up independently in one of the sessions. I had nothing to show back then. But now, there’s finally a prototype accomplishing a proof of concept. To be seen live in action at froglogic’s Qt Developer Days 2014 booth.

coco_coveragebrowser

(more…)