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

Commit 7d481d6

Browse files
authored
fix(ExpectedConditions): non-static ExpectedConditions for browser (#3766)
- Update sauce lab binary to run on travis. - Disable expected conditions test that forks the browser. This issue appears to not be specific to sauce labs. Also can reproduce this with a local driver provider. Additional work is required around driver providers and the runner. - Add TODO to enable test in the future when this is resolved. closes #3761
1 parent 12c5139 commit 7d481d6

File tree

7 files changed

+56
-43
lines changed

7 files changed

+56
-43
lines changed

lib/browser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class ProtractorBrowser extends Webdriver {
131131
/**
132132
* @type {ExpectedConditions}
133133
*/
134-
static ExpectedConditions = new ProtractorExpectedConditions();
134+
ExpectedConditions: ProtractorExpectedConditions;
135135

136136
/**
137137
* The wrapped webdriver instance. Use this to interact with pages that do
@@ -320,6 +320,9 @@ export class ProtractorBrowser extends Webdriver {
320320
this.trackOutstandingTimeouts_ = !opt_untrackOutstandingTimeouts;
321321
this.mockModules_ = [];
322322
this.addBaseMockModules_();
323+
324+
// set up expected conditions
325+
this.ExpectedConditions = new ProtractorExpectedConditions(this);
323326
}
324327

325328
/**

lib/expectedConditions.ts

+27-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import {ProtractorBrowser} from './browser';
12
import {ElementFinder} from './element';
2-
import {Ptor} from './ptor';
33

44
let webdriver = require('selenium-webdriver');
55

@@ -47,6 +47,8 @@ declare var global: any;
4747
* @constructor
4848
*/
4949
export class ProtractorExpectedConditions {
50+
constructor(public browser: ProtractorBrowser){};
51+
5052
/**
5153
* Negates the result of a promise.
5254
*
@@ -155,21 +157,18 @@ export class ProtractorExpectedConditions {
155157
*/
156158
alertIsPresent(): Function {
157159
return () => {
158-
return (<Ptor>global.protractor)
159-
.browser.driver.switchTo()
160-
.alert()
161-
.then(
162-
():
163-
boolean => {
164-
return true;
165-
},
166-
(err: any) => {
167-
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
168-
return false;
169-
} else {
170-
throw err;
171-
}
172-
});
160+
return this.browser.driver.switchTo().alert().then(
161+
():
162+
boolean => {
163+
return true;
164+
},
165+
(err: any) => {
166+
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
167+
return false;
168+
} else {
169+
throw err;
170+
}
171+
});
173172
};
174173
}
175174

@@ -261,11 +260,9 @@ export class ProtractorExpectedConditions {
261260
*/
262261
titleContains(title: string): Function {
263262
return () => {
264-
return (<Ptor>global.protractor)
265-
.browser.driver.getTitle()
266-
.then((actualTitle: string): boolean => {
267-
return actualTitle.indexOf(title) > -1;
268-
});
263+
return this.browser.driver.getTitle().then((actualTitle: string): boolean => {
264+
return actualTitle.indexOf(title) > -1;
265+
});
269266
};
270267
}
271268

@@ -285,11 +282,9 @@ export class ProtractorExpectedConditions {
285282
*/
286283
titleIs(title: string): Function {
287284
return () => {
288-
return (<Ptor>global.protractor)
289-
.browser.driver.getTitle()
290-
.then((actualTitle: string): boolean => {
291-
return actualTitle === title;
292-
});
285+
return this.browser.driver.getTitle().then((actualTitle: string): boolean => {
286+
return actualTitle === title;
287+
});
293288
};
294289
}
295290

@@ -310,11 +305,9 @@ export class ProtractorExpectedConditions {
310305
*/
311306
urlContains(url: string): Function {
312307
return () => {
313-
return (<Ptor>global.protractor)
314-
.browser.driver.getCurrentUrl()
315-
.then((actualUrl: string): boolean => {
316-
return actualUrl.indexOf(url) > -1;
317-
});
308+
return this.browser.driver.getCurrentUrl().then((actualUrl: string): boolean => {
309+
return actualUrl.indexOf(url) > -1;
310+
});
318311
};
319312
}
320313

@@ -334,11 +327,9 @@ export class ProtractorExpectedConditions {
334327
*/
335328
urlIs(url: string): Function {
336329
return () => {
337-
return (<Ptor>global.protractor)
338-
.browser.driver.getCurrentUrl()
339-
.then((actualUrl: string): boolean => {
340-
return actualUrl === url;
341-
});
330+
return this.browser.driver.getCurrentUrl().then((actualUrl: string): boolean => {
331+
return actualUrl === url;
332+
});
342333
};
343334
}
344335

lib/runner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class Runner extends EventEmitter {
167167
protractor.element = browser_.element;
168168
protractor.by = protractor.By = ProtractorBrowser.By;
169169
protractor.wrapDriver = ProtractorBrowser.wrapDriver;
170-
protractor.ExpectedConditions = ProtractorBrowser.ExpectedConditions;
170+
protractor.ExpectedConditions = browser_.ExpectedConditions;
171171

172172
if (!this.config_.noGlobals) {
173173
// Export protractor to the global namespace to be used in tests.

scripts/sauce_connect_setup.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ set -e
1212
# before_script:
1313
# - curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh | bash
1414

15-
CONNECT_URL="https://saucelabs.com/downloads/sc-4.4.0-linux.tar.gz"
15+
CONNECT_URL="https://saucelabs.com/downloads/sc-4.4.1-linux.tar.gz"
1616
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
17-
CONNECT_DOWNLOAD="sc-4.4.0-linux.tar.gz"
17+
CONNECT_DOWNLOAD="sc-4.4.1-linux.tar.gz"
1818

1919
CONNECT_LOG="$LOGS_DIR/sauce-connect"
2020
CONNECT_STDOUT="$LOGS_DIR/sauce-connect.stdout"
@@ -52,4 +52,4 @@ sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY $ARGS \
5252
# If you need to debug sauce connect, use the full output like so:
5353
#
5454
# sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY $ARGS \
55-
# --logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT &
55+
# --logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT &

spec/basic/expected_conditions_spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,23 @@ describe('expected conditions', function() {
176176
expect(EC.or(valid, EC.and(valid, invalid)).call()).toBe(true);
177177
expect(EC.or(EC.not(valid), EC.and(valid, invalid)).call()).toBe(false);
178178
});
179+
180+
// TODO(cnishina): enable test when local / sauce labs errors
181+
// are resolved.
182+
xdescribe('for forked browsers', function() {
183+
// ensure that we can run EC on forked browser instances
184+
it('should have alertIsPresent', function() {
185+
var browser2 = browser.forkNewDriverInstance();
186+
browser2.get('index.html#/form');
187+
var EC2 = browser2.ExpectedConditions;
188+
var alertIsPresent = EC2.alertIsPresent();
189+
expect(alertIsPresent.call()).toBe(false);
190+
191+
var alertButton = browser2.$('#alertbutton');
192+
alertButton.click();
193+
browser2.wait(EC2.alertIsPresent(), 1000);
194+
195+
browser2.switchTo().alert().accept();
196+
});
197+
});
179198
});

spec/basic/handling_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('handling timeout errors', function() {
55
browser.get('http://dummyUrl', 1).then(function() {
66
throw 'did not handle error';
77
}, function(err) {
8-
expect(err).toBeDefined();
8+
expect(err instanceof Error).toBeTruthy();
99
});
1010
});
1111
});

spec/dependencyTest/protractor_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('require(\'protractor\')', () => {
4242
});
4343

4444
it('should have static variables defined', () => {
45-
var staticVariables = ['By', 'ExpectedConditions'];
45+
var staticVariables = ['By'];
4646
for (var pos in staticVariables) {
4747
var property = staticVariables[pos];
4848
expect(typeof protractor.ProtractorBrowser[property]).toEqual('object');

0 commit comments

Comments
 (0)