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

chore(test): move interaction test off of the control flow #5019

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var passingTests = [
'node built/cli.js spec/plugins/browserGetSyncedConf.js',
'node built/cli.js spec/plugins/browserGetUnsyncedConf.js',
'node built/cli.js spec/plugins/waitForAngularConf.js',
// 'node built/cli.js spec/interactionConf.js',
'node built/cli.js spec/interactionConf.js',
// 'node built/cli.js spec/directConnectConf.js',
// 'node built/cli.js spec/restartBrowserBetweenTestsConf.js',
// 'node built/cli.js spec/driverProviderLocalConf.js',
Expand Down
163 changes: 83 additions & 80 deletions spec/interaction/interaction_spec.js
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, this comes from:

browser_.ready =

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.

Copy link
Contributor Author

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

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);
});
});
});
1 change: 1 addition & 0 deletions spec/interactionConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var env = require('./environment.js');
// Test having two browsers interacting with each other.
exports.config = {
seleniumAddress: env.seleniumAddress,
SELENIUM_PROMISE_MANAGER: false,

framework: 'jasmine',

Expand Down