Skip to content

Commit

Permalink
fix(ExpectedConditions): non-static ExpectedConditions for browser
Browse files Browse the repository at this point in the history
- 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 angular#3761
  • Loading branch information
cnishina committed Dec 1, 2016
1 parent 70bc6ea commit f3bb285
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 43 deletions.
5 changes: 4 additions & 1 deletion lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ProtractorBrowser extends Webdriver {
/**
* @type {ExpectedConditions}
*/
static ExpectedConditions = new ProtractorExpectedConditions();
ExpectedConditions: ProtractorExpectedConditions;

/**
* The wrapped webdriver instance. Use this to interact with pages that do
Expand Down Expand Up @@ -320,6 +320,9 @@ export class ProtractorBrowser extends Webdriver {
this.trackOutstandingTimeouts_ = !opt_untrackOutstandingTimeouts;
this.mockModules_ = [];
this.addBaseMockModules_();

// set up expected conditions
this.ExpectedConditions = new ProtractorExpectedConditions(this);
}

/**
Expand Down
63 changes: 27 additions & 36 deletions lib/expectedConditions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ProtractorBrowser} from './browser';
import {ElementFinder} from './element';
import {Ptor} from './ptor';

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

Expand Down Expand Up @@ -47,6 +47,8 @@ declare var global: any;
* @constructor
*/
export class ProtractorExpectedConditions {
constructor(public browser: ProtractorBrowser){};

/**
* Negates the result of a promise.
*
Expand Down Expand Up @@ -155,21 +157,18 @@ export class ProtractorExpectedConditions {
*/
alertIsPresent(): Function {
return () => {
return (<Ptor>global.protractor)
.browser.driver.switchTo()
.alert()
.then(
():
boolean => {
return true;
},
(err: any) => {
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
return false;
} else {
throw err;
}
});
return this.browser.driver.switchTo().alert().then(
():
boolean => {
return true;
},
(err: any) => {
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
return false;
} else {
throw err;
}
});
};
}

Expand Down Expand Up @@ -261,11 +260,9 @@ export class ProtractorExpectedConditions {
*/
titleContains(title: string): Function {
return () => {
return (<Ptor>global.protractor)
.browser.driver.getTitle()
.then((actualTitle: string): boolean => {
return actualTitle.indexOf(title) > -1;
});
return this.browser.driver.getTitle().then((actualTitle: string): boolean => {
return actualTitle.indexOf(title) > -1;
});
};
}

Expand All @@ -285,11 +282,9 @@ export class ProtractorExpectedConditions {
*/
titleIs(title: string): Function {
return () => {
return (<Ptor>global.protractor)
.browser.driver.getTitle()
.then((actualTitle: string): boolean => {
return actualTitle === title;
});
return this.browser.driver.getTitle().then((actualTitle: string): boolean => {
return actualTitle === title;
});
};
}

Expand All @@ -310,11 +305,9 @@ export class ProtractorExpectedConditions {
*/
urlContains(url: string): Function {
return () => {
return (<Ptor>global.protractor)
.browser.driver.getCurrentUrl()
.then((actualUrl: string): boolean => {
return actualUrl.indexOf(url) > -1;
});
return this.browser.driver.getCurrentUrl().then((actualUrl: string): boolean => {
return actualUrl.indexOf(url) > -1;
});
};
}

Expand All @@ -334,11 +327,9 @@ export class ProtractorExpectedConditions {
*/
urlIs(url: string): Function {
return () => {
return (<Ptor>global.protractor)
.browser.driver.getCurrentUrl()
.then((actualUrl: string): boolean => {
return actualUrl === url;
});
return this.browser.driver.getCurrentUrl().then((actualUrl: string): boolean => {
return actualUrl === url;
});
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Runner extends EventEmitter {
protractor.element = browser_.element;
protractor.by = protractor.By = ProtractorBrowser.By;
protractor.wrapDriver = ProtractorBrowser.wrapDriver;
protractor.ExpectedConditions = ProtractorBrowser.ExpectedConditions;
protractor.ExpectedConditions = browser_.ExpectedConditions;

if (!this.config_.noGlobals) {
// Export protractor to the global namespace to be used in tests.
Expand Down
6 changes: 3 additions & 3 deletions scripts/sauce_connect_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ set -e
# before_script:
# - curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh | bash

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

CONNECT_LOG="$LOGS_DIR/sauce-connect"
CONNECT_STDOUT="$LOGS_DIR/sauce-connect.stdout"
Expand Down Expand Up @@ -52,4 +52,4 @@ sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY $ARGS \
# If you need to debug sauce connect, use the full output like so:
#
# sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY $ARGS \
# --logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT &
# --logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT &
19 changes: 19 additions & 0 deletions spec/basic/expected_conditions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,23 @@ describe('expected conditions', function() {
expect(EC.or(valid, EC.and(valid, invalid)).call()).toBe(true);
expect(EC.or(EC.not(valid), EC.and(valid, invalid)).call()).toBe(false);
});

// TODO(cnishina): enable test when local / sauce labs errors
// are resolved.
xdescribe('for forked browsers', function() {
// ensure that we can run EC on forked browser instances
it('should have alertIsPresent', function() {
var browser2 = browser.forkNewDriverInstance();
browser2.get('index.html#/form');
var EC2 = browser2.ExpectedConditions;
var alertIsPresent = EC2.alertIsPresent();
expect(alertIsPresent.call()).toBe(false);

var alertButton = browser2.$('#alertbutton');
alertButton.click();
browser2.wait(EC2.alertIsPresent(), 1000);

browser2.switchTo().alert().accept();
});
});
});
2 changes: 1 addition & 1 deletion spec/basic/handling_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('handling timeout errors', function() {
browser.get('http://dummyUrl', 1).then(function() {
throw 'did not handle error';
}, function(err) {
expect(err).toBeDefined();
expect(err instanceof Error).toBeTruthy();
});
});
});
2 changes: 1 addition & 1 deletion spec/dependencyTest/protractor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('require(\'protractor\')', () => {
});

it('should have static variables defined', () => {
var staticVariables = ['By', 'ExpectedConditions'];
var staticVariables = ['By'];
for (var pos in staticVariables) {
var property = staticVariables[pos];
expect(typeof protractor.ProtractorBrowser[property]).toEqual('object');
Expand Down

0 comments on commit f3bb285

Please sign in to comment.