From 53bae686175f21182f4a1d3b35a15cee1db5a7e5 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 31 Oct 2018 14:26:51 +0200 Subject: [PATCH] test: make `elements` integration tests less flaky (#26869) PR Close #26869 --- integration/ng_elements/e2e/app.e2e-spec.ts | 20 +++++++++++--------- integration/ng_elements/src/app.ts | 2 -- integration/ng_elements/src/main.ts | 7 ++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/integration/ng_elements/e2e/app.e2e-spec.ts b/integration/ng_elements/e2e/app.e2e-spec.ts index 3cf0e87759..84acb3505b 100644 --- a/integration/ng_elements/e2e/app.e2e-spec.ts +++ b/integration/ng_elements/e2e/app.e2e-spec.ts @@ -1,20 +1,22 @@ -import { browser, element, by } from 'protractor'; +import { browser, element, ExpectedConditions as EC, by } from 'protractor'; browser.waitForAngularEnabled(false); describe('Element E2E Tests', function () { describe('Hello World Elements', () => { - it('should display: Hello world!', function () { - browser.get('hello-world.html'); - const helloWorldEl = element(by.css('hello-world-el')); + const helloWorldEl = element(by.css('hello-world-el')); + + beforeEach(() => browser.get('hello-world.html')); + + it('should display "Hello World!"', function () { expect(helloWorldEl.getText()).toEqual('Hello World!'); }); - it('should display: Hello Foo! via name attribute', function () { - browser.get('hello-world.html'); - const helloWorldEl = element(by.css('hello-world-el')); + it('should display "Hello Foo!" via name attribute', function () { const input = element(by.css('input[type=text]')); - ['f', 'o', 'o'].forEach((key) => input.sendKeys(key)); - expect(helloWorldEl.getText()).toEqual('Hello foo!'); + input.sendKeys('Foo'); + + // Make tests less flaky on CI by waiting up to 5s for the element text to be updated. + browser.wait(EC.textToBePresentInElement(helloWorldEl, 'Hello Foo!'), 5000); }); }); }); diff --git a/integration/ng_elements/src/app.ts b/integration/ng_elements/src/app.ts index 4b5767efcc..689930c4f9 100644 --- a/integration/ng_elements/src/app.ts +++ b/integration/ng_elements/src/app.ts @@ -19,5 +19,3 @@ export class AppModule { } ngDoBootstrap() {} } - -export {HelloWorldComponent}; diff --git a/integration/ng_elements/src/main.ts b/integration/ng_elements/src/main.ts index 545db04a1f..e1e39da4b0 100644 --- a/integration/ng_elements/src/main.ts +++ b/integration/ng_elements/src/main.ts @@ -3,11 +3,8 @@ import {AppModuleNgFactory} from './app.ngfactory'; platformBrowser().bootstrapModuleFactory(AppModuleNgFactory, {ngZone: 'noop'}); +const input = document.querySelector('input'); const helloWorld = document.querySelector('hello-world-el'); -const input = document.querySelector('input[type=text]'); if(input && helloWorld){ - input.addEventListener('input', e => { - const newText = (e.target as any).value; - helloWorld.setAttribute('name', newText); - }); + input.addEventListener('input', () => helloWorld.setAttribute('name', input.value)); }