Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7172e48

Browse files
authoredNov 9, 2018
chore(test): move interaction test off of the control flow (#5019)
1 parent 7b77acf commit 7172e48

File tree

3 files changed

+85
-81
lines changed

3 files changed

+85
-81
lines changed
 

‎scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var passingTests = [
2828
'node built/cli.js spec/plugins/browserGetSyncedConf.js',
2929
'node built/cli.js spec/plugins/browserGetUnsyncedConf.js',
3030
'node built/cli.js spec/plugins/waitForAngularConf.js',
31-
// 'node built/cli.js spec/interactionConf.js',
31+
'node built/cli.js spec/interactionConf.js',
3232
// 'node built/cli.js spec/directConnectConf.js',
3333
'node built/cli.js spec/restartBrowserBetweenTestsConf.js',
3434
// 'node built/cli.js spec/driverProviderLocalConf.js',

‎spec/interaction/interaction_spec.js

Lines changed: 83 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,137 @@
1-
describe('Browser', function() {
1+
class Person {
22

3-
var newBrowser;
3+
constructor(name, browser) {
4+
this.name = name;
5+
this.browser = browser;
6+
this.$ = browser.$;
7+
this.element = browser.element;
8+
}
49

5-
afterEach(function(done) {
10+
async openApp() {
11+
await this.browser.get('index.html#/interaction');
12+
};
13+
14+
async login() {
15+
await this.element(by.model('userInput')).sendKeys(this.name);
16+
await this.$('#sendUser').click();
17+
};
18+
19+
async clearMessages() {
20+
await this.$('#clearMessages').click();
21+
};
22+
23+
async sendMessage(msg) {
24+
await this.element(by.model('message')).sendKeys(msg);
25+
await this.$('#sendMessage').click();
26+
};
27+
28+
getMessages() {
29+
return this.element.all(by.repeater('msg in messages track by $index'));
30+
};
31+
};
32+
33+
describe('Browser', () => {
34+
35+
let newBrowser;
36+
37+
afterEach(async() => {
638
// Calling quit will remove the browser.
739
// You can choose to not quit the browser, and protractor will quit all of
840
// them for you when it exits (i.e. if you need a static number of browsers
941
// throughout all of your tests). However, I'm forking browsers in my tests
1042
// and don't want to pile up my browser count.
1143
if (newBrowser) {
12-
newBrowser.quit().then(() => {
13-
done();
14-
});
15-
} else {
16-
done();
44+
await newBrowser.quit();
1745
}
1846
});
1947

20-
it('should be able to fork', function() {
21-
browser.get('index.html');
22-
newBrowser = browser.forkNewDriverInstance();
48+
it('should be able to fork', async() => {
49+
await browser.get('index.html');
50+
newBrowser = await browser.forkNewDriverInstance().ready;
2351
expect(newBrowser).not.toEqual(browser);
2452
expect(newBrowser.driver).not.toEqual(browser.driver);
25-
expect(newBrowser.driver.getCurrentUrl()).toEqual('data:,');
53+
expect(await newBrowser.driver.getCurrentUrl()).toEqual('data:,');
2654
});
2755

28-
it('should be able to navigate to same url on fork', function() {
29-
browser.get('index.html');
30-
newBrowser = browser.forkNewDriverInstance(true);
31-
expect(newBrowser.driver.getCurrentUrl()).
32-
toMatch('index.html#/form');
56+
it('should be able to navigate to same url on fork', async() => {
57+
await browser.get('index.html');
58+
newBrowser = await browser.forkNewDriverInstance(true).ready;
59+
expect(await newBrowser.driver.getCurrentUrl()).toMatch('index.html#/form');
3360
});
3461

35-
it('should be able to copy mock modules on fork', function() {
36-
var mockModule = function() {
37-
var newModule = angular.module('mockModule', []);
62+
it('should be able to copy mock modules on fork', async() => {
63+
const mockModule = () => {
64+
const newModule = angular.module('mockModule', []);
3865
newModule.value('version', '2');
3966
};
4067

4168
browser.addMockModule('mockModule', mockModule);
42-
browser.get('index.html');
69+
await browser.get('index.html');
4370

44-
newBrowser = browser.forkNewDriverInstance(true, true);
45-
expect(newBrowser.element(by.css('[app-version]')).getText()).toEqual('2');
71+
newBrowser = await browser.forkNewDriverInstance(true, true).ready;
72+
expect(await newBrowser.element(by.css('[app-version]')).getText())
73+
.toEqual('2');
4674
});
4775

4876

49-
describe('Multiple browsers', function() {
77+
describe('Multiple browsers', () => {
5078

51-
var Person = function(name, browser) {
52-
var $ = browser.$;
53-
var element = browser.element;
54-
55-
this.openApp = function() {
56-
browser.get('index.html#/interaction');
57-
};
58-
59-
this.login = function() {
60-
element(by.model('userInput')).sendKeys(name);
61-
$('#sendUser').click();
62-
};
63-
64-
this.clearMessages = function() {
65-
$('#clearMessages').click();
66-
};
67-
68-
this.sendMessage = function(msg) {
69-
element(by.model('message')).sendKeys(msg);
70-
$('#sendMessage').click();
71-
};
72-
73-
this.getMessages = function() {
74-
return element.all(by.repeater('msg in messages track by $index'));
75-
};
76-
};
79+
7780

78-
var p0, p1;
81+
let p0, p1;
7982

80-
beforeEach(function() {
83+
beforeEach(async() => {
8184
// default browser.
8285
p0 = new Person('p0', browser);
83-
p0.openApp();
84-
p0.login();
85-
p0.clearMessages();
86+
await p0.openApp();
87+
await p0.login();
88+
await p0.clearMessages();
8689

8790
// Any additional browsers can be instantiated via browser.forkNewDriverInstance().
88-
newBrowser = browser.forkNewDriverInstance(true);
91+
newBrowser = await browser.forkNewDriverInstance(true).ready;
8992
p1 = new Person('p1', newBrowser);
90-
p1.openApp();
91-
p1.login();
93+
await p1.openApp();
94+
await p1.login();
9295
});
9396

94-
it('should be able to interact', function() {
95-
expect(p0.getMessages().count()).toEqual(0);
97+
it('should be able to interact', async() => {
98+
expect(await p0.getMessages().count()).toEqual(0);
9699

97-
p0.sendMessage('p0');
98-
browser.sleep(100); // The app polls every 100ms for updates.
99-
expect(p0.getMessages().count()).toEqual(1);
100-
expect(p1.getMessages().count()).toEqual(1);
100+
await p0.sendMessage('p0');
101+
await browser.sleep(100); // The app polls every 100ms for updates.
102+
expect(await p0.getMessages().count()).toEqual(1);
103+
expect(await p1.getMessages().count()).toEqual(1);
101104

102-
p1.sendMessage('p1');
103-
browser.sleep(100); // The app polls every 100ms for updates.
104-
expect(p0.getMessages().count()).toEqual(2);
105-
expect(p1.getMessages().count()).toEqual(2);
105+
await p1.sendMessage('p1');
106+
await browser.sleep(100); // The app polls every 100ms for updates.
107+
expect(await p0.getMessages().count()).toEqual(2);
108+
expect(await p1.getMessages().count()).toEqual(2);
106109
});
107110

108-
it('should perform actions in sync', function() {
109-
var ACTIONS = 10;
110-
expect(p0.getMessages().count()).toEqual(0);
111+
it('should perform actions in sync', async() => {
112+
const ACTIONS = 10;
113+
expect(await p0.getMessages().count()).toEqual(0);
111114

112-
var expectedMessages = [];
113-
var i;
115+
let expectedMessages = [];
116+
let i;
114117
for (i = 0; i < ACTIONS; ++i) {
115-
p0.sendMessage(i);
118+
await p0.sendMessage(i);
116119
expectedMessages.push('p0: ' + i);
117120
}
118121
for (i = 0; i < ACTIONS; ++i) {
119-
p1.sendMessage(i);
122+
await p1.sendMessage(i);
120123
expectedMessages.push('p1: ' + i);
121124
}
122125
for (i = 0; i < ACTIONS; ++i) {
123-
p0.sendMessage(i);
124-
p1.sendMessage(i);
126+
await p0.sendMessage(i);
127+
await p1.sendMessage(i);
125128
expectedMessages.push('p0: ' + i);
126129
expectedMessages.push('p1: ' + i);
127130
}
128131

129-
browser.sleep(100); // The app polls every 100ms for updates.
130-
expect(p0.getMessages().getText()).toEqual(expectedMessages);
131-
expect(p1.getMessages().getText()).toEqual(expectedMessages);
132+
await browser.sleep(100); // The app polls every 100ms for updates.
133+
expect(await p0.getMessages().getText()).toEqual(expectedMessages);
134+
expect(await p1.getMessages().getText()).toEqual(expectedMessages);
132135
});
133136
});
134137
});

‎spec/interactionConf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var env = require('./environment.js');
33
// Test having two browsers interacting with each other.
44
exports.config = {
55
seleniumAddress: env.seleniumAddress,
6+
SELENIUM_PROMISE_MANAGER: false,
67

78
framework: 'jasmine',
89

0 commit comments

Comments
 (0)
This repository has been archived.