Skip to content

Commit a99eb16

Browse files
gkalpakvicb
authored andcommitted
test(aio): make e2e tests less flakey
closes angular#20117
1 parent e36bac9 commit a99eb16

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

aio/e2e/app.e2e-spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { element, by } from 'protractor';
1+
import { browser, by, element } from 'protractor';
22
import { SitePage } from './app.po';
33

44
describe('site App', function() {
@@ -11,7 +11,7 @@ describe('site App', function() {
1111
});
1212

1313
it('should show features text after clicking "Features"', () => {
14-
page.getLink('features').click();
14+
page.getTopMenuLink('features').click();
1515
expect(page.getDocViewerText()).toMatch(/Progressive web apps/i);
1616
});
1717

@@ -21,7 +21,7 @@ describe('site App', function() {
2121
expect(page.getDocViewerText()).toMatch(/Tutorial: Tour of Heroes/i);
2222

2323
// navigate to a different page
24-
page.getLink('features').click();
24+
page.getTopMenuLink('features').click();
2525
expect(page.getDocViewerText()).toMatch(/Progressive web apps/i);
2626

2727
// Show the menu
@@ -42,6 +42,8 @@ describe('site App', function() {
4242
describe('scrolling to the top', () => {
4343
it('should scroll to the top when navigating to another page', () => {
4444
page.navigateTo('guide/security');
45+
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
46+
4547
page.scrollToBottom();
4648
page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0));
4749

@@ -51,6 +53,8 @@ describe('site App', function() {
5153

5254
it('should scroll to the top when navigating to the same page', () => {
5355
page.navigateTo('guide/security');
56+
browser.sleep(1000); // Wait for initial async scroll-to-top after `onDocRendered`.
57+
5458
page.scrollToBottom();
5559
page.getScrollTop().then(scrollTop => expect(scrollTop).toBeGreaterThan(0));
5660

@@ -85,7 +89,7 @@ describe('site App', function() {
8589

8690
it('should call ga with new URL on navigation', done => {
8791
let path: string;
88-
page.getLink('features').click();
92+
page.getTopMenuLink('features').click();
8993
page.locationPath()
9094
.then(p => path = p)
9195
.then(() => page.ga().then(calls => {

aio/e2e/app.po.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export class SitePage {
2323
.filter(element => element.getText().then(text => pattern.test(text)))
2424
.first();
2525
}
26-
getLink(path) { return element(by.css(`a[href="${path}"]`)); }
26+
getTopMenuLink(path) { return element(by.css(`aio-top-menu a[href="${path}"]`)); }
2727
ga() { return browser.executeScript('return window["ga"].q') as promise.Promise<any[][]>; }
2828
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
2929

3030
navigateTo(pageUrl = '') {
3131
return browser.get('/' + pageUrl)
3232
// We need to tell the index.html not to load the real analytics library
3333
// See the GA snippet in index.html
34-
.then(() => browser.driver.executeScript('sessionStorage.setItem("__e2e__", true);'));
34+
.then(() => browser.executeScript('sessionStorage.setItem("__e2e__", true);'));
3535
}
3636

3737
getDocViewerText() {

0 commit comments

Comments
 (0)