TagState Sample

Description
This sample script contains some user-defined functions used to gather and compare tag (text) information about child windows of a window. It also includes a simple usage of the functions on the PhantomTarget application. The functions can be used to compare entries in an application dialog against expected entries, or to verify that the entries did (or did not) change during a testing process.

Some of the Phantom features used are:

- Window Sibling/Child Functions
- Window Variable Members
- User Functions
- Loops
- Arrays
- Exceptions

To use this sample, simply copy and paste it into a new script and save it where the PhantomTarget application is located.

[ Back to Samples ]

TagState
# Phantom Sample Script
# This script declares two functions.  The first function,
# 'GetTagState' returns an array containing the tags
# of all the child windows of an input window.  The
# second function compares an array of strings with the
# tags of the children of the input window.
#
# The second part of the script uses the PhantomTarget
# application to illustrate the use of the functions.
#
# This sample illustrates how to access child windows
# and how to use arrays.  It also illustrates user-
# defined functions and exception usage.

##########################################################
# Functions
##########################################################

# This function returns the tag of all child windows
# and returns it as a string array
function
string GetTagState(window Parent){
  string Ret;    # The return array
  int ctr = 0;   # A local counter
  # Get the first child of the input window
  window Child = Parent.GetChild();
  
  # Cycle through child windows and get tags
  while(Child){
    Ret[ctr] = Child.Tag;
    Child = Child.GetNextSibling();
    ctr++;
  }
  # Return the array
  return Ret;
}

# This function checks the tags of all child windows
# against an input array.  The function returns an
# error exception if a tag does not match.
function
exception CheckTagState(window Parent, string Arr){
  # Prepare the return exception, setting it to OK
  exception e;
  e.SetOK("OK");
  
  # A local counter
  int ctr = 0;
  # Get the first child window
  window Child = Parent.GetChild();
  
  # Cycle through all children and compare tags
  while(Child){
    # If the tag doesnt match, produce an exception
    if(Child.Tag != Arr[ctr]){
      e.SetError("Tag does not match: " + Child.Tag + "; " + Arr[ctr]);
      return e;
    }
    Child = Child.GetNextSibling();
    ctr++;
  }
  
  # All tags matched, return OK
  return e;
}

##########################################################
# Script
##########################################################

# Sample use of functions

# Start PhantomTarget and create a window
# representing it
System("..\\PhantomTarget.exe");
window Target;
Target.Tag = "Phantom Target";
Target.Class = "*";

# Open the PushButton control dialog and
# create a window representing it
Target.TypeKeys("h");
window Buttons;
Buttons.Tag = "Button Dialog";
Buttons.Class = "*";

# Speed up execution
SetDelay(0);

# Add a child window representing Button 1
window Button1;
Button1.Tag = "Button &1";
Button1.Class = "Button";
Buttons.AddChild(Button1, "Button1");

# Get the tag states of the Button Dialog
string arr = GetTagState(Buttons);
disp(arr);

# Check to see that the text of all children
# is still the same.
exception e = CheckTagState(Buttons, arr);
if(e.GetState() != 1){  # 1 is OK state
  e.throw();
}else{
  disp("Check Result: Tags match");
}

# Click a button.  This will change the state
# of the 'Status' field.
Buttons.Button1.Click();

# Show that now an error is retutned because
# the states have changed.
disp(CheckTagState(Buttons, arr));

# Close the PhantomTarget application
Target.Close();



Copyright © 2000-2009 Phantom Automated Solutions, Inc.
[ Home ] [ Contact ] [ Privacy Policy ] [System Requirements]