MultiApp Sample

Description
This is a simple sample that illustrates how to automate multiple applications using Phantom. The script simulates a simple user interaction between the Window Declarations Recorder (WinDR) and Phantom Target utilities, both of which are included with the Phantom installation.

The script uses the MouseClick function to use WinDR to automatically record and save the window declarations of the Phantom Target application. A 'mouse down' of the left mouse button is simulated to grab the WinDR cross-hairs. A MouseMove function is then used to move the cross-hairs to the title bar of Phantom Target. Notice that the MouseMove is now applied to the Phantom Target window (Target). In this way, all coordinates remain with respect to the target application. In the 'mouse down', the intent is to click the cross-hairs button, so the MouseClick is applied to the Finder (cross-hairs) button. For the release, the cross-hairs are moved to the Phantom Target window, so the MouseClick is applied to the Target (Phantom Target). In this way, the script works regardless of the relative positions of WinDR and Phantom Target. To complete the recording, the mouse is released using MouseClick. Note again, here the MouseClick is applied to Phantom Target, as the coordinates specified are with respect to the Phantom Target application.

Once the mouse is released, the declarations for Phantom Target are recorded by WinDR. The script then saves the window declarations to a file. This step uses the Blink function to first visually verify that the FileName edit field corresponds to the 7th edit field in WinDR. Since edits and other controls often do not have a text tag (i.e., they have a numeric tag), it can be difficult to determine what control they refer to. Using the Blink function visually 'blinks' the control, so that it can be verified which control is referred to by the variable (in this case, that the FileName variable refers to the File Name edit field). This Blink statement is not required for this script to operate, but is included to show the use of Blink and how it can be an effective tool to understand what window a particular tag and class refers to.

To continue the save action, a test file name is applied to the FileName edit field, and the 'Save' button is clicked. Once the 'Save' button is clicked, WinDR displays the captured window declarations. In this case, the declarations are accepted as is, and the script clicks the 'OK' button.

Finally, the script closes both WinDR and the Phantom Target application.

Note that this script builds the window variables directly using the MainWin functions and the tags and classes of the windows. The tags and classes can be found by manually using WinDR and dragging the cross-hairs over the window or control of interest. Alternatively, WinDR can be manually used to create a window declarations file for WinDR and/or Phantom Target, and the resulting declarations loaded using the 'include' keyword. In this case, the window variables were created directly in this script so that separate declarations files do not need to be included. In general, the use of window declarations files will make scripts more compact and understandable, particularly when many scripts are used to automate the same window.

Some of the features of Phantom explored in this script are:

- Use of the System function to start an application
- Manually creating window variables (using MainWin)
- Mouse functions
- Using the Window Declarations Recorder
- Button interaction
- Edit field interaction
- Numeric window tags

To use this sample, simply copy and paste it into a new script and save it.

[ Back to Samples ]

MultiApp.psc
# This sample script illustrates how to use Phantom to automate
# multiple applications.  The script opens the Window Declarations
# Recorder and Phantom Target utilities that are packaged with
# the Phantom installation.
#
# The script then simulates mouse interaction to automate the
# process of using the Window Declarations Recorder to record
# and save the window declarations of Phantom Target.
#####################################################################

# Change these directories if Phantom was installed in a
# different location.
System("c:\\Program Files\\Phantom\\WinDR.exe");
System("c:\\Program Files\\Phantom\\PhantomTarget.exe");

# Build the window variables used in this script.  Alternatively,
# a window declarations file could be built using WinDR.  WinDR
# can be used to verify the tag and class for each of these windows.

# Declare the Window Declarations Recorder window
window WinDR = MainWin("Window Declarations Recorder", "#32770");
# Declare the 'cross-hairs' finder button in WinDR
window Finder = WinDR.MainWin("FINDER", "Button");
# Declare the FileName edit field in WinDR.  This is the 7th edit
# field that appears in the WinDR GUI.
window FileName = WinDR.MainWin(7, "Edit");
# Declare the Save button in WinDR.  The '&' is because the letter
# 'S' is an accelerator key (pushing <ALT>+S will activate it)
window SaveButton = WinDR.MainWin("&Save", "Button");
# Declare the main Phantom Target window
window Target = MainWin("Phantom Target", "*");
# Declare the window that will show the recorded window declarations.
window Viewer = MainWin("Window Declarations", "#32770");
# Declare the OK button in the Window Declarations viewer
window ViewerOK = Viewer.MainWin("&OK", "Button");

# Ensure the WinDR application is active
WinDR.SetActive();
# Use a 'mouse down' command to click the left mouse button
# (1st parameter = 0) 'down' (4th parameter = 1)  at coordinates
# 10,10.  This will 'grab' the finder cross-hairs.
Finder.MouseClick(0, 10, 10, 1);

# Move the cross-hairs to the title bar of the Phantom Target
# application.  The y coordinate, -30, can be found by using
# WinDR manually and seeing the Client Coordinates of the window
# title bar.
Target.MouseMove(30, -30);
# Release (4th parameter = 2) the left mouse button in the title
# bar.  This releases the cross-hairs, allowing WinDR to record the
# window information.
Target.MouseClick(0, 30, -30, 2);

# Now, the declarations will be saved to a file.  First, the 'Blink'
# command will be used to verify visually that the FileName window
# declared previously really is the 'File Name' field in WinDR.
# This can be taken out, and is only included to illustrate the use
# of 'Blink'.
FileName.Blink(4);
# Set the file name
FileName.SetText("TestDec.dec");
# Click the Save Button in WinDR.
SaveButton.Click();

# Once WinDR saves the declarations, it opens a viewer to show the
# contents of the declarations.  In this case, OK is clicked to
# accept the window declarations as is.
ViewerOK.Click();

# The script is complete, so close WinDR and the Phantom Target.
WinDR.Close();
Target.Close();

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