Squish tip of the week: Clipboard Access

Squish tip of the week: Clipboard Access

With the clipboard function in Squish Version 6.1 there will be an option to write text to the system clipboard and to get text from the system clipboard back into your automated test suite.

This feature will work on all platforms & languages and will help users solving issues getting access to the system clipboard. Furthermore it enhances the functionality of BDD in a time- and script efficient approach.

Snippet

Writing text to the system clipboard:
setClipboardText()
Getting text from the system clipboard:
getClipboardText()

Example 1:

In the following Address book example we assume that we have two (or more) entries with the same surname but different forenames. With the clipboard feature we can use the given surname across the whole test case without changing every entry in the code.

Furthermore if the surname is changing during the test we can set the new name into the clipboard with setClipboardText and get it back with getClipboardText in a efficient way.

def main():
    startApplication("Addressbook")
    mouseClick(waitForObjectItem(":Address Book - Unnamed_Menubar", "File"))
    mouseClick(waitForObjectItem(":File_MenuItem", "New"))
    mouseClick(waitForObject(":New_ToolbarItem"))
    mouseClick(waitForObject(":Add_ToolbarItem"))
    type(waitForObject(":Address Book - Add.Forename:_Edit"), "Peter")
    type(waitForObject(":Address Book - Add.Surname:_Edit"), "Mueller")
    type(waitForObject(":Address Book - Add.Email:_Edit"), "pm@gmail.com")
    type(waitForObject(":Address Book - Add.Phone:_Edit"), "007")
    clickButton(waitForObject(":Address Book - Add.OK_Button"))
    setClipboardText(waitForObject(":1_2_TableCell").text)
    mouseClick(waitForObject(":Add_ToolbarItem"))
    type(waitForObject(":Address Book - Add.Forename:_Edit"), "Dirk")
    type(waitForObject(":Address Book - Add.Surname:_Edit"), getClipboardText())
    type(waitForObject(":Address Book - Add.Email:_Edit"), "dm@gmail.com")
    type(waitForObject(":Address Book - Add.Phone:_Edit"), "006")
    clickButton(waitForObject(":Address Book - Add.OK_Button"))
    mouseClick(waitForObjectItem(":Address Book - Unnamed_Menubar", "File"))
    mouseClick(waitForObjectItem(":File_MenuItem", "Quit"))
    clickButton(waitForObject(":Address Book.No_Button"))

Example 2:

Another useful implementation is to verify values written by the AUT to the clipboard.

def main():
    startApplication("squishide")
    mouseClick(waitForObjectItem(":Window", "Run"))
    mouseClick(waitForObjectItem(":Menu", "Launch AUT"))
    mouseClick(waitForObjectItem(":Tree", "Address_Book___Unnamed_Window_0"), MouseButton.SecondaryButton)
    mouseClick(waitForObjectItem(":ContextMenu", "Copy Real Name"))
    mouseClick(waitForObjectItem(":MenuBar", "Run"))
    mouseClick(waitForObjectItem(":Menu", "Quit AUT"))
    test.compare(getClipboardText(), "{text='Address Book - Unnamed' type='Window'}");
    test.log(getClipboardText())

Example test results after running the test case (click image to enlarge)



How would you use the clipboard function? Please let us know in the comments below.


Related topics