From 03a1a5c0e9559cb5699be440ec1459dd486daea1 Mon Sep 17 00:00:00 2001 From: Adina Parpalita Date: Sat, 9 May 2020 03:36:28 -0700 Subject: [PATCH] fix flaky tests (#1461) --- e2e/components/search/search-input.ts | 2 +- e2e/suites/actions/edit-folder.test.ts | 11 ++++--- e2e/suites/actions/library-actions.test.ts | 4 +++ e2e/utilities/utils.ts | 34 +++++++++++----------- protractor.conf.js | 6 ++-- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/e2e/components/search/search-input.ts b/e2e/components/search/search-input.ts index 59803fb43..7ce179ad7 100755 --- a/e2e/components/search/search-input.ts +++ b/e2e/components/search/search-input.ts @@ -47,7 +47,7 @@ export class SearchInput extends Component { } async waitForSearchInputToBeInteractive() { - waitForClickable(this.searchControl); + await waitForClickable(this.searchControl); } async isSearchContainerDisplayed() { diff --git a/e2e/suites/actions/edit-folder.test.ts b/e2e/suites/actions/edit-folder.test.ts index 812208154..e58aa8e2e 100755 --- a/e2e/suites/actions/edit-folder.test.ts +++ b/e2e/suites/actions/edit-folder.test.ts @@ -108,14 +108,17 @@ describe('Edit folder', () => { await Promise.all([ apis.admin.sites.deleteSite(sitePrivate), apis.user.sites.deleteSite(siteName), - apis.user.nodes.deleteNodesById([ parentId, folderFavoriteToEditId, folderFavoriteDuplicateId, folderSearchToEditId ]) + apis.user.nodes.deleteNodesById([parentId, folderFavoriteToEditId, folderFavoriteDuplicateId, folderSearchToEditId]) ]); done(); }); - afterEach(async (done) => { + beforeEach(async () => { await Utils.pressEscape(); - done(); + }); + + afterEach(async () => { + await page.closeOpenDialogs(); }); it('[C216331] dialog UI defaults', async () => { @@ -167,7 +170,7 @@ describe('Edit folder', () => { }); it('[C216333] with name with special characters', async () => { - const namesWithSpecialChars = [ 'a*a', 'a"a', 'aa', `a\\a`, 'a/a', 'a?a', 'a:a', 'a|a' ]; + const namesWithSpecialChars = ['a*a', 'a"a', 'aa', `a\\a`, 'a/a', 'a?a', 'a:a', 'a|a']; await dataTable.selectItem(folderName); await toolbar.openMoreMenu(); diff --git a/e2e/suites/actions/library-actions.test.ts b/e2e/suites/actions/library-actions.test.ts index a1fbb32f2..de747cedf 100755 --- a/e2e/suites/actions/library-actions.test.ts +++ b/e2e/suites/actions/library-actions.test.ts @@ -87,6 +87,10 @@ describe('Library actions', () => { done(); }); + beforeEach(async () => { + await Utils.pressEscape(); + }); + afterEach(async (done) => { await Utils.pressEscape(); await page.header.expandSideNav(); diff --git a/e2e/utilities/utils.ts b/e2e/utilities/utils.ts index c68f5cfa5..912228e0c 100755 --- a/e2e/utilities/utils.ts +++ b/e2e/utilities/utils.ts @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . */ -import { browser, protractor, ElementFinder, ExpectedConditions as EC, by, logging, until } from 'protractor'; +import { browser, protractor, ElementFinder, ExpectedConditions as EC, by, logging, until, WebElement } from 'protractor'; import { Logger } from '@alfresco/adf-testing'; import { BROWSER_WAIT_TIMEOUT, E2E_ROOT_PATH } from '../configs'; @@ -31,21 +31,21 @@ const path = require('path'); const fs = require('fs'); const StreamZip = require('node-stream-zip'); -export async function typeText(element: ElementFinder, text: string) { +export async function typeText(element: ElementFinder, text: string): Promise { await element.clear(); await element.sendKeys(text); } -export async function clearTextWithBackspace(element: ElementFinder) { +export async function clearTextWithBackspace(element: ElementFinder): Promise { await element.clear(); await element.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE); } -export async function waitElement(css: string, errorMessage?: string): Promise { +export async function waitElement(css: string, errorMessage?: string): Promise { return browser.wait( until.elementLocated(by.css(css)), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting for element' + errorMessage || `Timeout waiting for element: ${css}` ); } @@ -53,10 +53,10 @@ export async function waitForClickable( element: ElementFinder, errorMessage?: string ): Promise { - return browser.wait( + await browser.wait( EC.elementToBeClickable(element), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting for element to be clickable' + errorMessage || `Timeout waiting for element to be clickable: ${element.locator()}` ); } @@ -64,10 +64,10 @@ export async function waitForVisibility( element: ElementFinder, errorMessage?: string ): Promise { - return browser.wait( + await browser.wait( EC.visibilityOf(element), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting for element visibility' + errorMessage || `Timeout waiting for element visibility: ${element.locator()}` ); } @@ -75,10 +75,10 @@ export async function waitForInvisibility( element: ElementFinder, errorMessage?: string ): Promise { - return browser.wait( + await browser.wait( EC.invisibilityOf(element), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting for element visibility' + errorMessage || `Timeout waiting for element visibility: ${element.locator()}` ); } @@ -86,10 +86,10 @@ export async function waitForPresence( element: ElementFinder, errorMessage?: string ): Promise { - return browser.wait( + await browser.wait( EC.presenceOf(element), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting for element presence' + errorMessage || `Timeout waiting for element presence: ${element.locator()}` ); } @@ -97,10 +97,10 @@ export async function waitForStaleness( element: ElementFinder, errorMessage?: string ): Promise { - return browser.wait( + await browser.wait( EC.stalenessOf(element), BROWSER_WAIT_TIMEOUT, - errorMessage || 'Timeout waiting element staleness' + errorMessage || `Timeout waiting element staleness: ${element.locator()}` ); } @@ -171,9 +171,9 @@ export class Utils { let tries = 15; - return new Promise(function(resolve) { + return new Promise(function (resolve) { const checkExist = setInterval(() => { - fs.access(filePath, function(error) { + fs.access(filePath, function (error) { tries--; if (error && tries === 0) { diff --git a/protractor.conf.js b/protractor.conf.js index b9693f977..e2f5ffcf1 100755 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -9,9 +9,9 @@ const fs = require('fs'); const projectRoot = path.resolve(__dirname); const downloadFolder = `${projectRoot}/e2e-downloads`; -const E2E_HOST = process.env.E2E_HOST || 'http://localhost', - E2E_PORT = process.env.E2E_PORT || 4200, - BROWSER_RUN = process.env.BROWSER_RUN; +const E2E_HOST = process.env.E2E_HOST || 'http://localhost'; +const E2E_PORT = process.env.E2E_PORT || 4200; +const BROWSER_RUN = process.env.BROWSER_RUN; const width = 1366; const height = 768;