Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit ab8d6a5

Browse files
committed
Adding better catching of async WebDriverJS errors, so that test flow
continues and all errors are reported via jasmine-node. Also, adding, but not yet enabling, tests for different types of ng-repeat format.
1 parent af8cbeb commit ab8d6a5

File tree

1 file changed

+91
-3
lines changed

1 file changed

+91
-3
lines changed

spec/testAppSpec.js

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,52 @@ var driver, ptor;
1919
driver.manage().timeouts().setScriptTimeout(10000);
2020
}());
2121

22+
var catchPromiseErrors = function(done) {
23+
webdriver.promise.controlFlow().
24+
on('uncaughtException', function(e) {
25+
done(e);
26+
});
27+
};
28+
2229
describe('test application', function() {
2330
describe('finding elements in forms', function() {
2431
beforeEach(function() {
2532
ptor.get('http://localhost:8000/app/index.html#/form');
2633
});
2734

2835
it('should find an element by binding', function(done) {
36+
catchPromiseErrors(done);
2937
ptor.findElement(protractor.By.binding('{{greeting}}')).
3038
getText().then(function(text) {
3139
expect(text).toEqual('Hiya');
3240
done();
3341
});
3442
});
3543

44+
it('should find an element by binding with attribute', function(done) {
45+
catchPromiseErrors(done);
46+
ptor.findElement(protractor.By.binding('username')).
47+
getText().then(function(text) {
48+
expect(text).toEqual('Anon');
49+
done();
50+
});
51+
});
52+
3653
it('should find an element by text input model', function(done) {
54+
catchPromiseErrors(done);
3755
var username = ptor.findElement(protractor.By.input('username'));
3856
username.clear();
3957
username.sendKeys('Jane Doe');
4058

41-
ptor.findElement(protractor.By.binding('{{username}}')).
59+
ptor.findElement(protractor.By.binding('username')).
4260
getText().then(function(text) {
4361
expect(text).toEqual('Jane Doe');
4462
done();
4563
});
4664
});
4765

4866
it('should find an element by checkbox input model', function(done) {
67+
catchPromiseErrors(done);
4968
ptor.findElement(protractor.By.id('shower')).
5069
isDisplayed().then(function(displayed) {
5170
expect(displayed).toBe(true);
@@ -58,6 +77,66 @@ describe('test application', function() {
5877
done();
5978
});
6079
});
80+
81+
xit('should find a repeater using data-ng-repeat', function(done) {
82+
catchPromiseErrors(done);
83+
ptor.findElement(protractor.By.repeater('day in days').row(3)).
84+
getText().then(function(text) {
85+
expect(text).toEqual('Wed');
86+
done();
87+
});
88+
ptor.findElement(protractor.By.repeater('day in days').row(3).
89+
column('day')).
90+
getText().then(function(text) {
91+
expect(text).toEqual('Wed');
92+
done();
93+
});
94+
});
95+
96+
xit('should find a repeater using ng:repeat', function(done) {
97+
catchPromiseErrors(done);
98+
ptor.findElement(protractor.By.repeater('bar in days').row(3)).
99+
getText().then(function(text) {
100+
expect(text).toEqual('Wed');
101+
done();
102+
});
103+
ptor.findElement(protractor.By.repeater('bar in days').row(3).
104+
column('bar')).
105+
getText().then(function(text) {
106+
expect(text).toEqual('Wed');
107+
done();
108+
});
109+
});
110+
111+
xit('should find a repeater using ng_repeat', function(done) {
112+
catchPromiseErrors(done);
113+
ptor.findElement(protractor.By.repeater('foo in days').row(3)).
114+
getText().then(function(text) {
115+
expect(text).toEqual('Wed');
116+
done();
117+
});
118+
ptor.findElement(protractor.By.repeater('foo in days').row(3)).
119+
column('foo').
120+
getText().then(function(text) {
121+
expect(text).toEqual('Wed');
122+
done();
123+
});
124+
});
125+
126+
xit('should find a repeater using x-ng-repeat', function(done) {
127+
catchPromiseErrors(done);
128+
ptor.findElement(protractor.By.repeater('qux in days').row(3)).
129+
getText().then(function(text) {
130+
expect(text).toEqual('Wed');
131+
done();
132+
});
133+
ptor.findElement(protractor.By.repeater('qux in days').row(3)).
134+
column('quz').
135+
getText().then(function(text) {
136+
expect(text).toEqual('Wed');
137+
done();
138+
});
139+
});
61140
});
62141

63142
describe('finding elements', function() {
@@ -66,6 +145,7 @@ describe('test application', function() {
66145
});
67146

68147
it('should find elements using a select', function(done) {
148+
catchPromiseErrors(done);
69149
ptor.findElement(protractor.By.selectedOption('planet')).
70150
getText().then(function(text) {
71151
expect(text).toEqual('Mercury');
@@ -83,6 +163,7 @@ describe('test application', function() {
83163
});
84164

85165
it('should find elements using a repeater', function(done) {
166+
catchPromiseErrors(done);
86167
// Returns the element for the entire row.
87168
ptor.findElement(protractor.By.repeater('ball in planets').row(3)).
88169
getText().then(function(text) {
@@ -111,6 +192,7 @@ describe('test application', function() {
111192
});
112193

113194
it('should find multiple elements by binding', function(done) {
195+
catchPromiseErrors(done);
114196
// There must be a better way to do this.
115197
ptor.findElement(protractor.By.select('planet'))
116198
.findElement(protractor.By.css('option[value="4"]')).click();
@@ -149,6 +231,7 @@ describe('test application', function() {
149231
});
150232

151233
it('should override services via mock modules', function(done) {
234+
catchPromiseErrors(done);
152235
ptor.addMockModule('moduleA', mockModuleA);
153236

154237
ptor.get('http://localhost:8000/app/index.html');
@@ -161,6 +244,7 @@ describe('test application', function() {
161244
});
162245

163246
it('should have the version of the last loaded module', function(done) {
247+
catchPromiseErrors(done);
164248
ptor.addMockModule('moduleA', mockModuleA);
165249
ptor.addMockModule('moduleB', mockModuleB);
166250

@@ -181,6 +265,7 @@ describe('test application', function() {
181265
});
182266

183267
it('should wait for slow RPCs', function(done) {
268+
catchPromiseErrors(done);
184269
var sample1Button = driver.findElement(protractor.By.id('sample1'));
185270
var sample2Button = driver.findElement(protractor.By.id('sample2'));
186271
sample1Button.click();
@@ -220,14 +305,17 @@ describe('test application', function() {
220305
});
221306

222307
it('should synchronize with a slow action', function(done) {
308+
catchPromiseErrors(done);
223309
var addOneButton = ptor.findElement(protractor.By.id('addone'));
224310
addOneButton.click();
225-
ptor.findElement(protractor.By.repeater("foo in foos | orderBy:'a':true").row(1).
311+
ptor.findElement(
312+
protractor.By.repeater("foo in foos | orderBy:'a':true").row(1).
226313
column('{{foo.b}}')).getText().then(function(text) {
227314
expect(text).toEqual('14930352');
228315
});
229316
addOneButton.click();
230-
ptor.findElement(protractor.By.repeater("foo in foos | orderBy:'a':true").row(1).
317+
ptor.findElement(
318+
protractor.By.repeater("foo in foos | orderBy:'a':true").row(1).
231319
column('{{foo.b}}')).getText().then(function(text) {
232320
expect(text).toEqual('24157817');
233321
done();

0 commit comments

Comments
 (0)