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

Commit 29f975a

Browse files
sjelinheathkit
authored andcommitted
feat(plugins): allow plugins to know which browser instance to run against (#4066)
Closes #4054
1 parent 9d69a81 commit 29f975a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/browser.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
659659
return this.driver.controlFlow()
660660
.execute(
661661
() => {
662-
return this.plugins_.waitForPromise();
662+
return this.plugins_.waitForPromise(this);
663663
},
664664
'Plugins.waitForPromise()')
665665
.then(() => {
666666
return this.driver.wait(() => {
667-
return this.plugins_.waitForCondition().then((results: boolean[]) => {
667+
return this.plugins_.waitForCondition(this).then((results: boolean[]) => {
668668
return results.reduce((x, y) => x && y, true);
669669
});
670670
}, this.allScriptsTimeout, 'Plugins.waitForCondition()');
@@ -860,7 +860,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
860860
url.resolve(this.baseUrl, destination);
861861
if (this.ignoreSynchronization) {
862862
return this.driver.get(destination)
863-
.then(() => this.driver.controlFlow().execute(() => this.plugins_.onPageLoad()))
863+
.then(() => this.driver.controlFlow().execute(() => this.plugins_.onPageLoad(this)))
864864
.then(() => null);
865865
}
866866

@@ -917,7 +917,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
917917
.then(() => {
918918
// Run Plugins
919919
return this.driver.controlFlow().execute(() => {
920-
return this.plugins_.onPageLoad();
920+
return this.plugins_.onPageLoad(this);
921921
});
922922
})
923923
.then(() => {
@@ -985,7 +985,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
985985
.then(() => {
986986
// Run Plugins
987987
return this.driver.controlFlow().execute(() => {
988-
return this.plugins_.onPageStable();
988+
return this.plugins_.onPageStable(this);
989989
});
990990
})
991991
.then(() => null);

lib/plugins.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as q from 'q';
22
import * as webdriver from 'selenium-webdriver';
33

4+
import {ProtractorBrowser} from './browser';
45
import {Config} from './config';
56
import {ConfigParser} from './configParser';
67
import {Logger} from './logger';
@@ -105,6 +106,8 @@ export interface ProtractorPlugin {
105106
* This is called inside browser.get() directly after the page loads, and before
106107
* angular bootstraps.
107108
*
109+
* @param {ProtractorBrowser} browser The browser instance which is loading a page.
110+
*
108111
* @this {Object} bound to module.exports
109112
*
110113
* @throws {*} If this function throws an error, a failed assertion is added to
@@ -114,13 +117,15 @@ export interface ProtractorPlugin {
114117
* protractor will wait for the promise to resolve before continuing. If
115118
* the promise is rejected, a failed assertion is added to the test results.
116119
*/
117-
onPageLoad?(): void|webdriver.promise.Promise<void>;
120+
onPageLoad?(browser: ProtractorBrowser): void|webdriver.promise.Promise<void>;
118121

119122
/**
120123
* This is called inside browser.get() directly after angular is done
121124
* bootstrapping/synchronizing. If browser.ignoreSynchronization is true, this
122125
* will not be called.
123126
*
127+
* @param {ProtractorBrowser} browser The browser instance which is loading a page.
128+
*
124129
* @this {Object} bound to module.exports
125130
*
126131
* @throws {*} If this function throws an error, a failed assertion is added to
@@ -130,14 +135,16 @@ export interface ProtractorPlugin {
130135
* protractor will wait for the promise to resolve before continuing. If
131136
* the promise is rejected, a failed assertion is added to the test results.
132137
*/
133-
onPageStable?(): void|webdriver.promise.Promise<void>;
138+
onPageStable?(browser: ProtractorBrowser): void|webdriver.promise.Promise<void>;
134139

135140
/**
136141
* Between every webdriver action, Protractor calls browser.waitForAngular() to
137142
* make sure that Angular has no outstanding $http or $timeout calls.
138143
* You can use waitForPromise() to have Protractor additionally wait for your
139144
* custom promise to be resolved inside of browser.waitForAngular().
140145
*
146+
* @param {ProtractorBrowser} browser The browser instance which needs invoked `waitForAngular`.
147+
*
141148
* @this {Object} bound to module.exports
142149
*
143150
* @throws {*} If this function throws an error, a failed assertion is added to
@@ -150,7 +157,7 @@ export interface ProtractorPlugin {
150157
* something other than a promise is returned, protractor will continue
151158
* onto the next command.
152159
*/
153-
waitForPromise?(): webdriver.promise.Promise<void>;
160+
waitForPromise?(browser: ProtractorBrowser): webdriver.promise.Promise<void>;
154161

155162
/**
156163
* Between every webdriver action, Protractor calls browser.waitForAngular() to
@@ -159,6 +166,8 @@ export interface ProtractorPlugin {
159166
* custom condition to be truthy. If specified, this function will be called
160167
* repeatedly until truthy.
161168
*
169+
* @param {ProtractorBrowser} browser The browser instance which needs invoked `waitForAngular`.
170+
*
162171
* @this {Object} bound to module.exports
163172
*
164173
* @throws {*} If this function throws an error, a failed assertion is added to
@@ -170,7 +179,7 @@ export interface ProtractorPlugin {
170179
* is returned, a failed assertion is added to the test results, and Protractor
171180
* will continue onto the next command.
172181
*/
173-
waitForCondition?(): webdriver.promise.Promise<boolean>|boolean;
182+
waitForCondition?(browser: ProtractorBrowser): webdriver.promise.Promise<boolean>|boolean;
174183

175184
/**
176185
* Used to turn off default checks for angular stability

0 commit comments

Comments
 (0)