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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/**
* Shared DSL statements that are useful to all scenarios.
*/
/**
* Usage:
* pause(seconds) pauses the test for specified number of seconds
*/
angular.scenario.dsl('pause', function() {
return function(time) {
return this.addFuture('pause for ' + time + ' seconds', function(done) {
this.setTimeout(function() { done(null, time * 1000); }, time * 1000);
});
};
});
/**
* Usage:
* expect(future).{matcher} where matcher is one of the matchers defined
* with angular.scenario.matcher
*
* ex. expect(binding("name")).toEqual("Elliott")
*/
angular.scenario.dsl('expect', function() {
var chain = angular.extend({}, angular.scenario.matcher);
chain.not = function() {
this.inverse = true;
return chain;
};
return function(future) {
this.future = future;
return chain;
};
});
/**
* Usage:
* navigateTo(future|string) where url a string or future with a value
* of a URL to navigate to
*/
angular.scenario.dsl('navigateTo', function() {
return function(url) {
var application = this.application;
var name = url;
if (url.name) {
name = ' value of ' + url.name;
}
return this.addFuture('navigate to ' + name, function(done) {
application.navigateTo(url.value || url, function() {
application.executeAction(function() {
if (this.angular) {
var $browser = this.angular.service.$browser();
$browser.poll();
$browser.notifyWhenNoOutstandingRequests(function() {
done(null, url.value || url);
});
} else {
done(null, url.value || url);
}
});
});
});
};
});
/**
* Usage:
* input(name).enter(value) enters value in input with specified name
* input(name).check() checks checkbox
* input(name).select(value) selects the readio button with specified name/value
*/
angular.scenario.dsl('input', function() {
var chain = {};
chain.enter = function(value) {
var spec = this;
return this.addFutureAction("input '" + this.name + "' enter '" + value + "'", function(done) {
var input = _jQuery(this.document).find('input[name=' + spec.name + ']');
if (!input.length)
return done("Input named '" + spec.name + "' does not exist.");
input.val(value);
this.angular.element(input[0]).trigger('change');
done();
});
};
chain.check = function() {
var spec = this;
return this.addFutureAction("checkbox '" + this.name + "' toggle", function(done) {
var input = _jQuery(this.document).
find('input:checkbox[name=' + spec.name + ']');
if (!input.length)
return done("Input named '" + spec.name + "' does not exist.");
this.angular.element(input[0]).trigger('click');
input.attr('checked', !input.attr('checked'));
done();
});
};
chain.select = function(value) {
var spec = this;
return this.addFutureAction("radio button '" + this.name + "' toggle '" + value + "'", function(done) {
var input = _jQuery(this.document).
find('input:radio[name$="@' + spec.name + '"][value="' + value + '"]');
if (!input.length)
return done("Input named '" + spec.name + "' does not exist.");
this.angular.element(input[0]).trigger('click');
input.attr('checked', !input.attr('checked'));
done();
});
};
return function(name) {
this.name = name;
return chain;
};
});
/**
* Usage:
* binding(name) returns the value of a binding
*/
angular.scenario.dsl('binding', function() {
return function(name) {
return this.addFutureAction("select binding '" + name + "'", function(done) {
var element = _jQuery(this.document).find('[ng\\:bind="' + name + '"]');
if (!element.length)
return done("Binding named '" + name + "' does not exist.");
done(null, element.text());
});
};
});
|