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';
describe('site App', function() {
@ -11,7 +11,7 @@ describe('site App', function() {
});
it('should show features text after clicking "Features"', () => {
page.getLink('features').click();
page.getTopMenuLink('features').click();
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);
// navigate to a different page
page.getLink('features').click();
page.getTopMenuLink('features').click();
expect(page.getDocViewerText()).toMatch(/Progressive web apps/i);
// Show the menu
@ -42,6 +42,8 @@ describe('site App', function() {
describe('scrolling to the top', () => {
it('should scroll to the top when navigating to another page', () => {
page.navigateTo('guide/security');
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
page.scrollToBottom();
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', () => {
page.navigateTo('guide/security');
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
page.scrollToBottom();
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 => {
let path: string;
page.getLink('features').click();
page.getTopMenuLink('features').click();
page.locationPath()
.then(p => path = p)
.then(() => page.ga().then(calls => {

View File

@ -23,7 +23,7 @@ export class SitePage {
.filter(element => element.getText().then(text => pattern.test(text)))
.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[][]>; }
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
@ -31,7 +31,7 @@ export class SitePage {
return browser.get('/' + pageUrl)
// We need to tell the index.html not to load the real analytics library
// See the GA snippet in index.html
.then(() => browser.driver.executeScript('sessionStorage.setItem("__e2e__", true);'));
.then(() => browser.executeScript('sessionStorage.setItem("__e2e__", true);'));
}
getDocViewerText() {