This repository was 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
chore(test): move interaction test off of the control flow #5019
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, this comes from:
protractor/lib/runner.ts
Line 275 in ed955e5
I think this is so convoluted because it needed to support the control flow case as well. This should be cleaned up - forkNewDriverInstance() should just return a promise that resolves to the new browser instance, after its ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this to a queue of issues to clean up for the selenium 4 upgrade milestone