fix(web_workers): make waitForElementText function more stable

This commit is contained in:
Jeff Cross 2016-02-25 14:07:02 -08:00
parent 4b3b5d7c53
commit f6a8d04c32
1 changed files with 11 additions and 8 deletions

View File

@ -1,6 +1,12 @@
import {verifyNoBrowserErrors} from 'angular2/src/testing/e2e_util'; import {verifyNoBrowserErrors} from 'angular2/src/testing/e2e_util';
describe("WebWorker Router", () => { describe("WebWorker Router", () => {
beforeEach(() => {
// This test can't wait for Angular 2 as Testability is not available when using WebWorker
browser.ignoreSynchronization = true;
browser.get('/');
});
afterEach(() => { afterEach(() => {
verifyNoBrowserErrors(); verifyNoBrowserErrors();
browser.ignoreSynchronization = false; browser.ignoreSynchronization = false;
@ -11,8 +17,6 @@ describe("WebWorker Router", () => {
var baseUrl = "playground/src/web_workers/router/index.html"; var baseUrl = "playground/src/web_workers/router/index.html";
it("should route on click", () => { it("should route on click", () => {
// This test can't wait for Angular 2 as Testability is not available when using WebWorker
browser.ignoreSynchronization = true;
browser.get(baseUrl); browser.get(baseUrl);
waitForElement(contentSelector); waitForElement(contentSelector);
@ -23,8 +27,8 @@ describe("WebWorker Router", () => {
aboutBtn.click(); aboutBtn.click();
waitForUrl(/\/about/); waitForUrl(/\/about/);
waitForElement(contentSelector); waitForElement(contentSelector);
waitForElementText(contentSelector, "About");
content = element(by.css(contentSelector)); content = element(by.css(contentSelector));
waitForElementText(content, "About");
expect(content.getText()).toEqual("About"); expect(content.getText()).toEqual("About");
expect(browser.getCurrentUrl()).toMatch(/\/about/); expect(browser.getCurrentUrl()).toMatch(/\/about/);
@ -32,20 +36,18 @@ describe("WebWorker Router", () => {
contactBtn.click(); contactBtn.click();
waitForUrl(/\/contact/); waitForUrl(/\/contact/);
waitForElement(contentSelector); waitForElement(contentSelector);
waitForElementText(contentSelector, "Contact");
content = element(by.css(contentSelector)); content = element(by.css(contentSelector));
waitForElementText(content, "Contact");
expect(content.getText()).toEqual("Contact"); expect(content.getText()).toEqual("Contact");
expect(browser.getCurrentUrl()).toMatch(/\/contact/); expect(browser.getCurrentUrl()).toMatch(/\/contact/);
}); });
it("should load the correct route from the URL", () => { it("should load the correct route from the URL", () => {
// This test can't wait for Angular 2 as Testability is not available when using WebWorker
browser.ignoreSynchronization = true;
browser.get(baseUrl + "#/about"); browser.get(baseUrl + "#/about");
waitForElement(contentSelector); waitForElement(contentSelector);
waitForElementText(contentSelector, "About");
let content = element(by.css(contentSelector)); let content = element(by.css(contentSelector));
waitForElementText(content, "About");
expect(content.getText()).toEqual("About"); expect(content.getText()).toEqual("About");
}); });
@ -53,9 +55,10 @@ describe("WebWorker Router", () => {
browser.wait(protractor.until.elementLocated(by.css(selector)), 15000); browser.wait(protractor.until.elementLocated(by.css(selector)), 15000);
} }
function waitForElementText(elem: protractor.ElementFinder, expected: string): void { function waitForElementText(contentSelector: string, expected: string): void {
browser.wait(() => { browser.wait(() => {
let deferred = protractor.promise.defer(); let deferred = protractor.promise.defer();
var elem = element(by.css(contentSelector));
elem.getText().then((text) => { return deferred.fulfill(text === expected); }); elem.getText().then((text) => { return deferred.fulfill(text === expected); });
return deferred.promise; return deferred.promise;
}, 5000); }, 5000);