Squish tip of the week: How to capture data for reuse later in test

Squish tip of the week: How to capture data for reuse later in test

A common question I hear from users is: Is it possible to capture data from my application, store it, and use it later in my test?

Quick Answer: Absolutely!

Using Squish’s object access functions, users can retrieve information about an object, it’s properties, values, etc.

Take an Inventory application for example. After entering a new item in inventory, a corresponding SKU is generated. Later in your test you may wish to confirm the generated SKU matches the SKU listed when searching for the inventory item by name.

function main(){
var newInventoryItem = new Array("Part ABC", "Manufacturer XYZ", "Available");
var newSKU = generateNewInventoryEntry(newInventoryItem);
var retrievedSKU = getSKUByInventoryName("Part ABC");
test.compare(newSKU, retrievedSKU, "Validating generated SKU matches SKU search result by item name");

function generateNewInventoryEntry(inventoryItem){
var inventoryFields = ["Part", "Manufacturer", "Status"];
for (var i = 0; i < inventoryItem.length; ++i) type(waitForObject(":Invnt." + inventoryFields[i] + ":_.JTextField"), inventoryItem[i]);
var generatedSKU = object.properties(waitForObject(":itemSKU_TableItem"));
return generatedSKU["text"];

function getSKUByInventoryName(itemName){
type(waitForObject(":SearchInventName:_JTextField"), itemName);
var properties = object.properties(waitForObject(":itemSKU_TableItem"));
return properties["text"];

Read more about Object Access Functions


Leave a reply

Your email address will not be published. Required fields are marked *