test(aio): make e2e tests less flakey

closes #20117
This commit is contained in:
George Kalpakas 2017-11-02 21:40:14 +02:00 committed by Victor Berchet
parent e36bac9e90
commit a99eb16320
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { element, by } from 'protractor'; import { browser, by, element } from 'protractor';
import { SitePage } from './app.po'; import { SitePage } from './app.po';
describe('site App', function() { describe('site App', function() {
@ -11,7 +11,7 @@ describe('site App', function() {
}); });
it('should show features text after clicking "Features"', () => { it('should show features text after clicking "Features"', () => {
page.getLink('features').click(); page.getTopMenuLink('features').click();
expect(page.getDocViewerText()).toMatch(/Progressive web apps/i); expect(page.getDocViewerText()).toMatch(/Progressive web apps/i);
}); });
@ -21,7 +21,7 @@ describe('site App', function() {
expect(page.getDocViewerText()).toMatch(/Tutorial: Tour of Heroes/i); expect(page.getDocViewerText()).toMatch(/Tutorial: Tour of Heroes/i);
// navigate to a different page // navigate to a different page
page.getLink('features').click(); page.getTopMenuLink('features').click();
expect(page.getDocViewerText()).toMatch(/Progressive web apps/i); expect(page.getDocViewerText()).toMatch(/Progressive web apps/i);
// Show the menu // Show the menu
@ -42,6 +42,8 @@ describe('site App', function() {
describe('scrolling to the top', () => { describe('scrolling to the top', () => {
it('should scroll to the top when navigating to another page', () => { it('should scroll to the top when navigating to another page', () => {
page.navigateTo('guide/security'); page.navigateTo('guide/security');
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
page.scrollToBottom(); page.scrollToBottom();
page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0)); page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0));
@ -51,6 +53,8 @@ describe('site App', function() {
it('should scroll to the top when navigating to the same page', () => { it('should scroll to the top when navigating to the same page', () => {
page.navigateTo('guide/security'); page.navigateTo('guide/security');
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
page.scrollToBottom(); page.scrollToBottom();
page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0)); page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0));
@ -85,7 +89,7 @@ describe('site App', function() {
it('should call ga with new URL on navigation', done => { it('should call ga with new URL on navigation', done => {
let path: string; let path: string;
page.getLink('features').click(); page.getTopMenuLink('features').click();
page.locationPath() page.locationPath()
.then(p => path = p) .then(p => path = p)
.then(() => page.ga().then(calls => { .then(() => page.ga().then(calls => {

View File

@ -23,7 +23,7 @@ export class SitePage {
.filter(element => element.getText().then(text => pattern.test(text))) .filter(element => element.getText().then(text => pattern.test(text)))
.first(); .first();
} }
getLink(path) { return element(by.css(`a[href="${path}"]`)); } getTopMenuLink(path) { return element(by.css(`aio-top-menu a[href="${path}"]`)); }
ga() { return browser.executeScript('return window["ga"].q') as promise.Promise<any[][]>; } ga() { return browser.executeScript('return window["ga"].q') as promise.Promise<any[][]>; }
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; } locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
@ -31,7 +31,7 @@ export class SitePage {
return browser.get('/' + pageUrl) return browser.get('/' + pageUrl)
// We need to tell the index.html not to load the real analytics library // We need to tell the index.html not to load the real analytics library
// See the GA snippet in index.html // See the GA snippet in index.html
.then(() => browser.driver.executeScript('sessionStorage.setItem("__e2e__", true);')); .then(() => browser.executeScript('sessionStorage.setItem("__e2e__", true);'));
} }
getDocViewerText() { getDocViewerText() {