After you have completed the project settings, create a script to test that the menu components are properly enabled. To do this, create a template for the script, then fill in the proper code using some of the API commands.
Let's see what happens when you try to select a menu component from the "Record/Playback" window.
TCTestCaseBuilder
, should be in place.
Java 1.1.x AWT MenuComponents
are specific to a platform. If JavaStar tried to address these components directly through the GUI itself, the resulting scripts would be platform dependent. Robust scripts should run on all platforms.
Because of this, there needs to be another means to address the Menu
Components
. There is: using the JavaStar API. You can use methods in the JSMenuComponent
class provided with JavaStar to get the actual MenuItem
, then use the MenuItem's
methods to do the verification.
This is a common use for the API: obtaining the component itself, then checking information about the component that is not available to you from the verification function within the "Record/Playback" window.
Although our example uses a menu component, parallel commands exist for a regular component. The menu class is JSMenuComponent
; a regular component is JSComponent
.
You can use the declarations generated for this application. To learn more about generating declarations, see "Generating Declarations".
Here is an example of locating a menu component:
JSMenuComponent newMenuComponent;
newMenuComponent = TCTesterDeclarations.Main.New();
This is not the AWT MenuItem
, though. Use the getValidUnique()
method of JSMenuComponent
(or JSComponent
) to extract the actual component from the JavaStar wrapper. As getValidUnique()
returns a generic Component
, you must downcast the component to the proper class.
MenuItem newMenuItem = (MenuItem) newMenuComponent.getUnique();
Once you have the MenuItem
, you can use its methods to verify. However, you'll need a means to report the results of that verification to the test.
You can make output assertions from within a script using the JS
static method, JS.check()
. JS.check()
takes two parameters: a boolean
that is the condition you want to check, and a String
that represents the purpose of the check.
The initial condition should be presented such that if it is true, the check will pass. For example, you assert that if the New menu item is enabled, this check should pass. You do this in code by writing:
JS.check(newMenuItem.isEnabled(), "New should be enabled");
Now that you've got the idea of what is needed, let's review the mechanics of getting this code into the script.
You could code the entire script by hand, but it would be subject to errors of omission for the items JavaStar provides that you shouldn't have to think too much about. It's easier to use the record features of JavaStar to generate a base script.
If you were really verifying the state of the application at start-up, you'd probably do the verifications of all buttons and text fields directly from the Record/Playback window, then edit the script to add the menu verifications. Feel free to do that if you have the time. Our directions are just for how to do the menu verification.
VerifyFileNotOpen
.
This created a script with an empty play()
method, except for obtaining a component. Now you need to edit that script to put in the code to verify the menu item.
Use the Script Editor within JavaStar to enter the required code. See "Editing Tests" in the JavaStar User's Guide for more information on using this editor.
tutorial/API/TCTester/Tests/VerifyFileNotOpen.java
play()
method.MenuItem newMenuItem;
JSMenuComponent newMenuComponent;
newMenuComponent = TCTesterDeclarations.Main.New();
newMenuItem = (MenuItem) newMenuComponent.getValidUnique();
JS.check(newMenuItem.isEnabled(), "New should be enabled");
Now that you've got a start on using the API, try a lesson that is a bit more complicated.
Send feedback to
JavaStar-feedback@suntest.com
Copyright © 1998
Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303.
All rights reserved.