forked from vkolgi/tuneup_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
51 lines (50 loc) · 1.54 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Run a new test with the given +title+ and function body, which will
* be executed within the proper test declarations for the UIAutomation
* framework. The given function will be handed a +UIATarget+ and
* a +UIApplication+ object which it can use to exercise and validate your
* application.
*
* The +options+ parameter is an optional object/hash thingie that
* supports the following:
* logTree -- a boolean to log the element tree when the test fails (default 'true')
*
* Example:
* test("Sign-In", function(target, application) {
* // exercise and validate your application.
* });
*
* The +title+ is checked against every element of a global TUNEUP_ONLY_RUN
* array. To check, each element is converted to a RegExp. The test is only
* executed, if one check succeeds. If TUNEUP_ONLY_RUN is not defined,
* no checks are performed.
*/
function test(title, f, options) {
if (typeof TUNEUP_ONLY_RUN !== 'undefined') {
for (var i = 0; i < TUNEUP_ONLY_RUN.length; i++) {
if (new RegExp("^" + TUNEUP_ONLY_RUN[i] + "$").test(title)) {
break;
}
if (i == TUNEUP_ONLY_RUN.length -1) {
return;
}
}
}
if (!options) {
options = {
logTree: true
};
}
target = UIATarget.localTarget();
application = target.frontMostApp();
UIALogger.logStart(title);
try {
f(target, application);
UIALogger.logPass(title);
}
catch (e) {
UIALogger.logError(e.toString());
if (options.logTree) target.logElementTree();
UIALogger.logFail(title);
}
}