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

fix(ExpectedConditions): non-static ExpectedConditions for browser #3766

Merged
merged 1 commit into from
Dec 1, 2016
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Nit: comments should be sentences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😞 Will fix in next PR...

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