This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): move interaction test off of the control flow (#5019)
- Loading branch information
Showing
3 changed files
with
85 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,137 @@ | ||
describe('Browser', function() { | ||
class Person { | ||
|
||
var newBrowser; | ||
constructor(name, browser) { | ||
this.name = name; | ||
this.browser = browser; | ||
this.$ = browser.$; | ||
this.element = browser.element; | ||
} | ||
|
||
afterEach(function(done) { | ||
async openApp() { | ||
await this.browser.get('index.html#/interaction'); | ||
}; | ||
|
||
async login() { | ||
await this.element(by.model('userInput')).sendKeys(this.name); | ||
await this.$('#sendUser').click(); | ||
}; | ||
|
||
async clearMessages() { | ||
await this.$('#clearMessages').click(); | ||
}; | ||
|
||
async sendMessage(msg) { | ||
await this.element(by.model('message')).sendKeys(msg); | ||
await this.$('#sendMessage').click(); | ||
}; | ||
|
||
getMessages() { | ||
return this.element.all(by.repeater('msg in messages track by $index')); | ||
}; | ||
}; | ||
|
||
describe('Browser', () => { | ||
|
||
let newBrowser; | ||
|
||
afterEach(async() => { | ||
// Calling quit will remove the browser. | ||
// You can choose to not quit the browser, and protractor will quit all of | ||
// them for you when it exits (i.e. if you need a static number of browsers | ||
// throughout all of your tests). However, I'm forking browsers in my tests | ||
// and don't want to pile up my browser count. | ||
if (newBrowser) { | ||
newBrowser.quit().then(() => { | ||
done(); | ||
}); | ||
} else { | ||
done(); | ||
await newBrowser.quit(); | ||
} | ||
}); | ||
|
||
it('should be able to fork', function() { | ||
browser.get('index.html'); | ||
newBrowser = browser.forkNewDriverInstance(); | ||
it('should be able to fork', async() => { | ||
await browser.get('index.html'); | ||
newBrowser = await browser.forkNewDriverInstance().ready; | ||
expect(newBrowser).not.toEqual(browser); | ||
expect(newBrowser.driver).not.toEqual(browser.driver); | ||
expect(newBrowser.driver.getCurrentUrl()).toEqual('data:,'); | ||
expect(await newBrowser.driver.getCurrentUrl()).toEqual('data:,'); | ||
}); | ||
|
||
it('should be able to navigate to same url on fork', function() { | ||
browser.get('index.html'); | ||
newBrowser = browser.forkNewDriverInstance(true); | ||
expect(newBrowser.driver.getCurrentUrl()). | ||
toMatch('index.html#/form'); | ||
it('should be able to navigate to same url on fork', async() => { | ||
await browser.get('index.html'); | ||
newBrowser = await browser.forkNewDriverInstance(true).ready; | ||
expect(await newBrowser.driver.getCurrentUrl()).toMatch('index.html#/form'); | ||
}); | ||
|
||
it('should be able to copy mock modules on fork', function() { | ||
var mockModule = function() { | ||
var newModule = angular.module('mockModule', []); | ||
it('should be able to copy mock modules on fork', async() => { | ||
const mockModule = () => { | ||
const newModule = angular.module('mockModule', []); | ||
newModule.value('version', '2'); | ||
}; | ||
|
||
browser.addMockModule('mockModule', mockModule); | ||
browser.get('index.html'); | ||
await browser.get('index.html'); | ||
|
||
newBrowser = browser.forkNewDriverInstance(true, true); | ||
expect(newBrowser.element(by.css('[app-version]')).getText()).toEqual('2'); | ||
newBrowser = await browser.forkNewDriverInstance(true, true).ready; | ||
expect(await newBrowser.element(by.css('[app-version]')).getText()) | ||
.toEqual('2'); | ||
}); | ||
|
||
|
||
describe('Multiple browsers', function() { | ||
describe('Multiple browsers', () => { | ||
|
||
var Person = function(name, browser) { | ||
var $ = browser.$; | ||
var element = browser.element; | ||
|
||
this.openApp = function() { | ||
browser.get('index.html#/interaction'); | ||
}; | ||
|
||
this.login = function() { | ||
element(by.model('userInput')).sendKeys(name); | ||
$('#sendUser').click(); | ||
}; | ||
|
||
this.clearMessages = function() { | ||
$('#clearMessages').click(); | ||
}; | ||
|
||
this.sendMessage = function(msg) { | ||
element(by.model('message')).sendKeys(msg); | ||
$('#sendMessage').click(); | ||
}; | ||
|
||
this.getMessages = function() { | ||
return element.all(by.repeater('msg in messages track by $index')); | ||
}; | ||
}; | ||
|
||
|
||
var p0, p1; | ||
let p0, p1; | ||
|
||
beforeEach(function() { | ||
beforeEach(async() => { | ||
// default browser. | ||
p0 = new Person('p0', browser); | ||
p0.openApp(); | ||
p0.login(); | ||
p0.clearMessages(); | ||
await p0.openApp(); | ||
await p0.login(); | ||
await p0.clearMessages(); | ||
|
||
// Any additional browsers can be instantiated via browser.forkNewDriverInstance(). | ||
newBrowser = browser.forkNewDriverInstance(true); | ||
newBrowser = await browser.forkNewDriverInstance(true).ready; | ||
p1 = new Person('p1', newBrowser); | ||
p1.openApp(); | ||
p1.login(); | ||
await p1.openApp(); | ||
await p1.login(); | ||
}); | ||
|
||
it('should be able to interact', function() { | ||
expect(p0.getMessages().count()).toEqual(0); | ||
it('should be able to interact', async() => { | ||
expect(await p0.getMessages().count()).toEqual(0); | ||
|
||
p0.sendMessage('p0'); | ||
browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(p0.getMessages().count()).toEqual(1); | ||
expect(p1.getMessages().count()).toEqual(1); | ||
await p0.sendMessage('p0'); | ||
await browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(await p0.getMessages().count()).toEqual(1); | ||
expect(await p1.getMessages().count()).toEqual(1); | ||
|
||
p1.sendMessage('p1'); | ||
browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(p0.getMessages().count()).toEqual(2); | ||
expect(p1.getMessages().count()).toEqual(2); | ||
await p1.sendMessage('p1'); | ||
await browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(await p0.getMessages().count()).toEqual(2); | ||
expect(await p1.getMessages().count()).toEqual(2); | ||
}); | ||
|
||
it('should perform actions in sync', function() { | ||
var ACTIONS = 10; | ||
expect(p0.getMessages().count()).toEqual(0); | ||
it('should perform actions in sync', async() => { | ||
const ACTIONS = 10; | ||
expect(await p0.getMessages().count()).toEqual(0); | ||
|
||
var expectedMessages = []; | ||
var i; | ||
let expectedMessages = []; | ||
let i; | ||
for (i = 0; i < ACTIONS; ++i) { | ||
p0.sendMessage(i); | ||
await p0.sendMessage(i); | ||
expectedMessages.push('p0: ' + i); | ||
} | ||
for (i = 0; i < ACTIONS; ++i) { | ||
p1.sendMessage(i); | ||
await p1.sendMessage(i); | ||
expectedMessages.push('p1: ' + i); | ||
} | ||
for (i = 0; i < ACTIONS; ++i) { | ||
p0.sendMessage(i); | ||
p1.sendMessage(i); | ||
await p0.sendMessage(i); | ||
await p1.sendMessage(i); | ||
expectedMessages.push('p0: ' + i); | ||
expectedMessages.push('p1: ' + i); | ||
} | ||
|
||
browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(p0.getMessages().getText()).toEqual(expectedMessages); | ||
expect(p1.getMessages().getText()).toEqual(expectedMessages); | ||
await browser.sleep(100); // The app polls every 100ms for updates. | ||
expect(await p0.getMessages().getText()).toEqual(expectedMessages); | ||
expect(await p1.getMessages().getText()).toEqual(expectedMessages); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters