Hi Squish Users!
Checkout the latest Squish Tip of the Week on our blog:
Squish tip of the week: Reuse script functions in BDD tests

With the introduction of BDD support, all the existing scripts aren’t lost – quite the contrary – existing scripts and functions still work as always, and now those functions can also be called by BDD tests.
Consider the following Test Suite Resource functions:

def invokeMenuItem(menu, item):
    activateItem(waitForObjectItem(":AB_QMenuBar", menu))
    activateItem(waitForObjectItem("{type='QMenu' \
    title='%s'}" % menu, item))
def addNameAndAddress(nameAndAddress):
    invokeMenuItem("Edit", "Add...")
    for fieldName, text in zip(("Forename", "Surname", \
                    "Email", "Phone"), nameAndAddress):
        type(waitForObject(":%s:_QLineEdit" % fieldName)\
             , text)
def checkNameAndAddress(record):    
    table = waitForObject(":Address Book_QTableWidget")
    for column in range(len(record)):
        test.compare(table.item(0, column).text(),
A traditional Script Test Case would appear as follows, using the functions directly:
Script Test Case
source(findFile("scripts", "sharedFunctions.py"))
def main():
    newEntry = ("Jane", "Smith", "jane@smith.com",\
    invokeMenuItem("File", "New")
A BDD Test Case would appear as follows:
Feature File
Scenario Outline: A first scenario in which the feature can be exercised
  Given the application is running
   And a new address book is open
  When a new entry '<forename>','<lastname>','<email>','<phone>' is added
  Then the info should match '<forename>','<lastname>','<email>','<phone>'
      | forename  | lastname | email          | phone        |
      | Jane      | Smith    | jane@smith.com | 123.123.1234 |
The BDD steps are automated by the Test Suite Resource’s Implementation File, available for reuse to all other BDD Test Cases in the Test Suite, and can be recorded or manually created.
BDD Test Case (Implementation File)
import __builtin__
source(findFile("scripts", "sharedFunctions.py"))
 @Given("the application is running")
def step(context):
 @Given("a new address book is open")
def step(context):
    invokeMenuItem("File", "New")
@When("a new entry '|word|','|word|','|any|','|any|' is added")
def step(context, forename, surname, email, phone):
    newEntry = (forename, surname, email, phone)
@Then("the info should match '|word|','|word|','|any|','|any|'")
def step(context, forename, surname, email, phone):
    newEntry = (forename, surname, email, phone)
Why transition?

  1. Faster test creation
  2. Optimized test maintenance
  3. And tests written in a business-readable language
  4. Not only are you reusing functions you’ve already implemented – but now you’re implementing new tests with even greater reuse capabilities – easily accessed using Statement Completion

Learn more here: