Information Technology Reference
In-Depth Information
The length function returns the number of items in an array.
Generating input events
You can set values for UI events by accessing their value property. For example
textFields[“username”].setValue(“Mr Anonymous”);
You can also automate button taps using the tap() function. For example
myButtons[“okButton”].tap();
An extended version of the same code can tap buttons on the built-in keyboard. For example
app.keyboard().elements().[“go”].tap();
taps the Go button.
If your application needs to wait after an event, use
target.delay(timeInSeconds);
Logging output
To log events and values, use calls to UIALogger , which displays messages in the script log window under the
time line. UIALogger has various message levels, which force messages to appear in different colors. For ex-
ample
UIALogger.logFail (“Something bad happened.”);
appears on the console in red.
Creating test scripts
Testing typically follows these steps:
1. Preset some UI elements with test values.
2. Perform an operation, sometimes using a button tap.
3. Pause if necessary.
4. Read return values and generate messages for pass/fail conditions or general reporting.
You can, of course, include various paths through the test sequence, depending on the test results.
Figure 16.33 shows a trivial example that runs a very simple test. In this example the code is unlikely to fail, be-
cause the number of text fields is fixed. But in a more complex test it can be useful to report the number of
items in a UI. For example, you can report the number of cells in a table view after loading data from a remote
source.
FIGURE 16.33
The output from a very simple test script
Search WWH ::




Custom Search