From 0cc9842bf676c8abd13890c0db030124c22a5298 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 24 Oct 2018 19:50:38 +0300 Subject: [PATCH] test(upgrade): make e2e tests for upgrade docs examples less flaky (#26726) PR Close #26726 --- .../upgrade-phonecat-1-typescript/e2e-spec.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/aio/content/examples/upgrade-phonecat-1-typescript/e2e-spec.ts b/aio/content/examples/upgrade-phonecat-1-typescript/e2e-spec.ts index ec98b44eb5..210034d7a9 100644 --- a/aio/content/examples/upgrade-phonecat-1-typescript/e2e-spec.ts +++ b/aio/content/examples/upgrade-phonecat-1-typescript/e2e-spec.ts @@ -1,6 +1,6 @@ 'use strict'; // necessary for es6 output in node -import { browser, element, by, ElementFinder } from 'protractor'; +import { browser, element, by, ElementArrayFinder, ElementFinder } from 'protractor'; // Angular E2E Testing Guide: // https://docs.angularjs.org/guide/e2e-testing @@ -20,6 +20,12 @@ describe('PhoneCat Application', function() { describe('View: Phone list', function() { + // Helpers + const waitForCount = (elems: ElementArrayFinder, count: number) => { + // Wait for the list to stabilize, which may take a while (e.g. due to animations). + browser.wait(() => elems.count().then(c => c === count), 5000); + }; + beforeEach(function() { browser.get('index.html#!/phones'); }); @@ -28,13 +34,16 @@ describe('PhoneCat Application', function() { let phoneList = element.all(by.repeater('phone in $ctrl.phones')); let query = element(by.model('$ctrl.query')); + waitForCount(phoneList, 20); expect(phoneList.count()).toBe(20); query.sendKeys('nexus'); + waitForCount(phoneList, 1); expect(phoneList.count()).toBe(1); query.clear(); query.sendKeys('motorola'); + waitForCount(phoneList, 8); expect(phoneList.count()).toBe(8); }); @@ -51,6 +60,7 @@ describe('PhoneCat Application', function() { } queryField.sendKeys('tablet'); // Let's narrow the dataset to make the assertions shorter + waitForCount(phoneNameColumn, 2); expect(getNames()).toEqual([ 'Motorola XOOM\u2122 with Wi-Fi', @@ -66,10 +76,16 @@ describe('PhoneCat Application', function() { }); it('should render phone specific links', function() { + let phoneList = element.all(by.repeater('phone in $ctrl.phones')); let query = element(by.model('$ctrl.query')); - query.sendKeys('nexus'); - element.all(by.css('.phones li a')).first().click(); + query.sendKeys('nexus'); + waitForCount(phoneList, 1); + + let nexusPhone = phoneList.first(); + let detailLink = nexusPhone.all(by.css('a')).first() + + detailLink.click(); expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s'); });