SLAlert Class Reference
Inherits from | NSObject |
Declared in | SLAlert.h |
Overview
The SLAlert
class allows access to, and control of, alerts within your application.
Alerts do not need to be handled by the tests. If they are not handled, they will be automatically dismissed (by tapping the cancel button, if the button exists, then tapping the default button, if one is identifiable).
A test may optionally specify an alternate handler for an alert, by constructing
an SLAlertHandler
from the SLAlert
that matches that alert, and registering that
handler with the SLAlertHandler
class. When a matching alert appears, the handler
dismisses the alert. The test then asks the handler to see if the alert was
dismissed as expected.
SLAlert *alert = [SLAlert alertWithTitle:@"foo];
// dismiss an alert with title "foo", when it appears
SLAlertHandler *handler = [alert dismiss];
[SLAlertHandler addHandler:handler];
// test causes an alert with title "foo" to appear
SLAssertTrueWithTimeout([handler didHandleAlert], SLAlertHandlerDidHandleAlertDelay, @"Alert did not appear.");
Warning: If a test wishes to manually handle an alert, it must register a handler before that alert appears.
Warning: If the alert has no cancel nor default button, it will not be able to be dismissed by any handler, and the tests will hang. (If the tests are being run via the command line, Instruments will eventually time out; if the tests are being run via the GUI, the developer will need to stop the tests.)
The methods in the SLAlert (Debugging)
category are to be used only to
debug Subliminal tests.
The methods in the SLAlert (Subclassing)
category are to be used only by
subclasses of SLAlert
.
Tasks
Matching Alerts
-
+ alertWithTitle:
Creates and returns an alert object that matches an alert view with the specified title.
Handling Alerts
-
– dismiss
Creates and returns a handler that dismisses a matching alert using the default handling behavior.
-
– dismissWithButtonTitled:
Creates and returns a handler that dismisses a matching alert by tapping the button with the specified title.
-
– setText:ofFieldOfType:
Creates and returns a handler that sets the text of the specified text field of a matching alert to a specified value.
Debugging Tests
-
– dismissByUser
Creates and returns a handler that relies on a user to dismiss an alert.
Methods for Subclasses
-
– isEqualToUIAAlertPredicate
Returns the body of a JS function which evaluates a
UIAAlert
to see if it matches the receiver.
Instance Methods
dismiss
Creates and returns a handler that dismisses a matching alert using the default handling behavior.
- (SLAlertDismissHandler *)dismiss
Return Value
A newly created handler that dismisses the corresponding alert using UIAutomation’s default procedure.
Discussion
Which is to tap the cancel button, if the button exists, else tapping the default button, if one is identifiable.
Warning: If the alert has no cancel nor default button, it will not be able to be dismissed and the tests will hang. (If the tests are being run via the command line, Instruments will eventually time out; if the tests are being run via the GUI, the developer can abort.)
Declared In
SLAlert.h
dismissByUser
Creates and returns a handler that relies on a user to dismiss an alert.
- (SLAlertDismissHandler *)dismissByUser
Return Value
A newly created handler that does not dismiss the corresponding alert, but rather relies on a live user to dismiss the alert.
Discussion
Warning: Subliminal will not dismiss an alert handled by this handler. This handler thus has a use only when debugging tests.
Declared In
SLAlert.h
dismissWithButtonTitled:
Creates and returns a handler that dismisses a matching alert by tapping the button with the specified title.
- (SLAlertDismissHandler *)dismissWithButtonTitled:(NSString *)buttonTitle
Parameters
- buttonTitle
The title of the button to tap to dismiss the alert.
Return Value
A newly created handler that dismisses the corresponding alert by tapping the button with the specified title.
Declared In
SLAlert.h
isEqualToUIAAlertPredicate
Returns the body of a JS function which
evaluates a UIAAlert
to see if it matches the receiver.
- (NSString *)isEqualToUIAAlertPredicate
Return Value
The body of a JS function which evaluates a UIAAlert “alert
”
to see if it matches a particular SLAlert
.
Discussion
The JS function will take one argument, “alert
” (a UIAAlert
), as argument,
and should return true if alert
is equivalent to the receiver, false otherwise.
This method should return the body of that function: one or more statements,
with no function closure.
The default implementation simply compares the titles of the receiving SLAlert
and provided UIAAlert
.
Declared In
SLAlert.h
setText:ofFieldOfType:
Creates and returns a handler that sets the text of the specified text field of a matching alert to a specified value.
- (SLAlertHandler *)setText:(NSString *)text ofFieldOfType:(SLAlertTextFieldType)fieldType
Parameters
- text
The text to enter into the field.
- fieldType
The type of text field, corresponding to the alert’s presentation style.
Return Value
A newly created handler that sets the text of the specified text field
of a matching alert to a text
.
Declared In
SLAlert.h