This lesson describes how to add parameters, using the script editor included with JavaStar. The JavaStar Script Editor includes a button for saving and compiling the modified code, making it convenient for this exercise. You can use any editor you like to edit the scripts--just make sure you compile the code when you are done.
This section covers:
OpenFile.java
for edit.OpenFile.java
. Double-click the filename or click Open.
JavaStar Script Editor
The play method opens with the line:
public void play(String[] args) throws Throwable {
test.db
reference with args[0]
.NameData.MainWin.frame().dialog("Open").relativefile(".",
"test.db");
"test.db"
to args[0]
. Leave the "."
parameter before the filename so that JavaStar knows to look for the database file in the current directory. Remove the quotation marks. The new line should read:
NameData.MainWin.frame().dialog("Open").relativefile(".",
args[0]);
Name Database - test.db
. This is done with this line:
NameData.MainWin.frame().member("java.awt.Label", "Name Database -
test.db").waitFor("Name Database -
test.db", "Proceed only if correct file loaded");
"Name Database - test.db"
to "Name Database - " + args[0]
. Be sure to change it in both places on this line--in the member()
and waitFor()
method calls--and include the plus-sign.
NameData.MainWin.frame().member("java.awt.Label", "Name Database -
" + args[0]).waitFor("Name Database -
" + args[0], "Proceed only if correct file loaded");
EnterFieldData.java
for edit.
public void play(String[] args) throws Throwable {
NameData.MainWin.nameTextField().typeString(
"Count Von Count", 0, 0);
"Count von Count", 0, 0
to args[0]
so that it reads:
NameData.MainWin.nameTextField().typeString(
args[0]);
(0,0)
that follow. The JavaStar API provides two versions of the of the typeString()
method--one requiring the string to replace, selection start, and selection end parameters, and the other requiring only the string to replace. Here you're replacing the default version recorded in the script with a simpler method call. That just replaces the entire contents of the text field.
"123 Numbers Lane", 0 ,0
to args[1]
.NameData.MainWin.address1TextField().typeString("123 Numbers Lane", 0, 0);
NameData.MainWin.address1TextField().typeString(args[1]);
"Transylvania", 0 ,0
to args[2]
.
NameData.MainWin.address2TextField().typeString("Transylvania", 0 ,0
);
NameData.MainWin.address1TextField().typeString(args[2]);
"01-2-34567", 0 ,0
to args[3]
.NameData.MainWin.telephoneTF().typeString("01-2-34567", 0, 0);
NameData.MainWin.telephoneTF().typeString(args[3]);
"count@count.com", 0 ,0
to args[4]
.NameData.MainWin.emailTextField().typeString("count@count.com", 0, 0);
NameData.MainWin.emailTextField().typeString(args[4]);
"Bean Counter", 0 ,0
to args[5]
.NameData.MainWin.otherTextField().typeString("Bean counter", 0, 0);
NameData.MainWin.otherTextField().typeString(args[5]);
DefineSearch.java
for edit.
NameData.SearchWin.containsStrTextField().
typeString("Transylvania", 0, 0);
NameData.SearchWin.containsStrTextField().typeString(args[0]);
Note - Argument references always start at 0 within a script. The argument value refers to the arguments position in the array of arguments passed to the script at runtime. It does not refer to an absolute position for all arguments passed into the JST.
GetSearchResults.java
for edit.Count von Count
record by name.
NameData.SearchWin.list().select(0,"Count Von Count");
"Count von Count"
with args[0]
so the line reads:
NameData.SearchWin.list().select(0,args[0]);
select
method. The JavaStar API provides another version of this method that selects an item using only the string. If you now plan to pass the string name to the script, you don't know what the position of that string will be within the list when this is executed as part of a test, so you need to perform the selection based solely on the string value.
0,
so the line reads:
JS.frame("Search").member("java.awt.List").select(args[0]);
VerifyRecord.java
for edit.Count von Count
record by name.
NameData.MainWin.nameTextField().verify(this,"Count von Count", "Verify expected field text");
"Count von Count"
to args[0]
so that it reads:
NameData.MainWin.nameTextField().verify(this, args[0], "Verify expected field text");
Replace | With |
---|---|
"123 Numbers Lane"
|
args[1]
|
"Transylvania"
|
args[2]
|
"01-2-34567"
|
args[3]
|
"count@count.com"
|
args[4]
|
"Bean Counter"
|
args[5]
|
Send feedback to
JavaStar-feedback@suntest.com
Copyright © 1998
Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303.
All rights reserved.