test: make elements integration tests less flaky (#26869)

PR Close #26869
This commit is contained in:
George Kalpakas 2018-10-31 14:26:51 +02:00 committed by Kara Erickson
parent 952ca59336
commit 53bae68617
3 changed files with 13 additions and 16 deletions

View File

@ -1,20 +1,22 @@
import { browser, element, by } from 'protractor'; import { browser, element, ExpectedConditions as EC, by } from 'protractor';
browser.waitForAngularEnabled(false); browser.waitForAngularEnabled(false);
describe('Element E2E Tests', function () { describe('Element E2E Tests', function () {
describe('Hello World Elements', () => { describe('Hello World Elements', () => {
it('should display: Hello world!', function () { const helloWorldEl = element(by.css('hello-world-el'));
browser.get('hello-world.html');
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!'); expect(helloWorldEl.getText()).toEqual('Hello World!');
}); });
it('should display: Hello Foo! via name attribute', function () { it('should display "Hello Foo!" via name attribute', function () {
browser.get('hello-world.html');
const helloWorldEl = element(by.css('hello-world-el'));
const input = element(by.css('input[type=text]')); const input = element(by.css('input[type=text]'));
['f', 'o', 'o'].forEach((key) => input.sendKeys(key)); input.sendKeys('Foo');
expect(helloWorldEl.getText()).toEqual('Hello 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);
}); });
}); });
}); });

View File

@ -19,5 +19,3 @@ export class AppModule {
} }
ngDoBootstrap() {} ngDoBootstrap() {}
} }
export {HelloWorldComponent};

View File

@ -3,11 +3,8 @@ import {AppModuleNgFactory} from './app.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory, {ngZone: 'noop'}); platformBrowser().bootstrapModuleFactory(AppModuleNgFactory, {ngZone: 'noop'});
const input = document.querySelector('input');
const helloWorld = document.querySelector('hello-world-el'); const helloWorld = document.querySelector('hello-world-el');
const input = document.querySelector('input[type=text]');
if(input && helloWorld){ if(input && helloWorld){
input.addEventListener('input', e => { input.addEventListener('input', () => helloWorld.setAttribute('name', input.value));
const newText = (e.target as any).value;
helloWorld.setAttribute('name', newText);
});
} }