From f5bbe820230aeaad6186f2c1a5b2ed88b24d44e1 Mon Sep 17 00:00:00 2001 From: Dmitry Lemeshko Date: Fri, 3 May 2019 20:12:15 +0200 Subject: [PATCH] adjust tests to pass on Firefox (#35597) * adjust tests to pass on Firefox * update feature controls tests to pass on Firefox * use xpath to search for index pattern --- .../apps/dashboard/create_and_add_embeddables.js | 3 ++- test/functional/apps/dashboard/dashboard_clone.js | 7 ++----- test/functional/page_objects/common_page.js | 6 +++++- test/functional/page_objects/settings_page.js | 3 ++- test/functional/page_objects/visualize_page.js | 11 +++++------ test/functional/services/find.ts | 8 ++++++++ test/functional/services/test_subjects.ts | 2 +- .../apps/canvas/feature_controls/canvas_security.ts | 8 ++------ .../apps/canvas/feature_controls/canvas_spaces.ts | 8 ++------ .../apps/maps/feature_controls/maps_security.ts | 5 +---- .../apps/maps/feature_controls/maps_spaces.ts | 5 +---- .../timelion/feature_controls/timelion_security.ts | 6 +----- .../apps/timelion/feature_controls/timelion_spaces.ts | 9 +++------ x-pack/test/functional/page_objects/security_page.js | 5 +++++ 14 files changed, 40 insertions(+), 46 deletions(-) diff --git a/test/functional/apps/dashboard/create_and_add_embeddables.js b/test/functional/apps/dashboard/create_and_add_embeddables.js index 84c16feef0b5..dfc472c7af05 100644 --- a/test/functional/apps/dashboard/create_and_add_embeddables.js +++ b/test/functional/apps/dashboard/create_and_add_embeddables.js @@ -44,10 +44,11 @@ export default function ({ getService, getPageObjects }) { await PageObjects.visualize.clickNewSearch(); await PageObjects.visualize.saveVisualizationExpectSuccess('visualization from add new link'); - return retry.try(async () => { + await retry.try(async () => { const panelCount = await PageObjects.dashboard.getPanelCount(); expect(panelCount).to.eql(originalPanelCount + 1); }); + await PageObjects.dashboard.waitForRenderComplete(); }); it('saves the saved visualization url to the app link', async () => { diff --git a/test/functional/apps/dashboard/dashboard_clone.js b/test/functional/apps/dashboard/dashboard_clone.js index 493c31578e35..867d92a46eef 100644 --- a/test/functional/apps/dashboard/dashboard_clone.js +++ b/test/functional/apps/dashboard/dashboard_clone.js @@ -76,12 +76,9 @@ export default function ({ getService, getPageObjects }) { await PageObjects.dashboard.clickClone(); await PageObjects.dashboard.confirmClone(); + await PageObjects.dashboard.expectDuplicateTitleWarningDisplayed({ displayed: true }); await PageObjects.dashboard.confirmClone(); - - // This is important since saving a new dashboard will cause a refresh of the page. We have to - // wait till it finishes reloading or it might reload the url after simulating the - // dashboard landing page click. - await PageObjects.header.waitUntilLoadingHasFinished(); + await PageObjects.dashboard.waitForRenderComplete(); const countOfDashboards = await PageObjects.dashboard.getDashboardCountWithName(dashboardName + ' Copy'); diff --git a/test/functional/page_objects/common_page.js b/test/functional/page_objects/common_page.js index 7d4b4bbf9916..e849bc847b6d 100644 --- a/test/functional/page_objects/common_page.js +++ b/test/functional/page_objects/common_page.js @@ -361,7 +361,11 @@ export function CommonPageProvider({ getService, getPageObjects }) { } async getBodyText() { - const el = await find.byCssSelector('body>pre'); + if (await find.existsByCssSelector('a[id=rawdata-tab]')) { + // Firefox has 3 tabs and requires navigation to see Raw output + await find.clickByCssSelector('a[id=rawdata-tab]'); + } + const el = await find.byCssSelector('body pre'); return await el.getVisibleText(); } } diff --git a/test/functional/page_objects/settings_page.js b/test/functional/page_objects/settings_page.js index f7589f24a1f0..6dbf086ddf61 100644 --- a/test/functional/page_objects/settings_page.js +++ b/test/functional/page_objects/settings_page.js @@ -281,7 +281,8 @@ export function SettingsPageProvider({ getService, getPageObjects }) { } async clickIndexPatternLogstash() { - await find.clickByPartialLinkText('logstash-*'); + const indexLink = await find.byXPath(`//a[descendant::*[text()='logstash-*']]`); + await indexLink.click(); } async createIndexPattern(indexPatternName, timefield = '@timestamp') { diff --git a/test/functional/page_objects/visualize_page.js b/test/functional/page_objects/visualize_page.js index 589e2bd4ee3f..d9507e361bc9 100644 --- a/test/functional/page_objects/visualize_page.js +++ b/test/functional/page_objects/visualize_page.js @@ -385,13 +385,12 @@ export function VisualizePageProvider({ getService, getPageObjects, updateBaseli } async getGaugeValue() { - const elements = await find.allByCssSelector('[data-test-subj="visualizationLoader"] .chart svg'); + const elements = await find.allByCssSelector('[data-test-subj="visualizationLoader"] .chart svg text'); const values = await Promise.all(elements.map(async element => { const text = await element.getVisibleText(); - return text.split('\n'); + return text; })); - // .flat() replacement - return values.reduce((acc, val) => [...acc, ...val], []); + return values.filter(item => item.length > 0); } async clickMetricEditor() { @@ -678,10 +677,10 @@ export function VisualizePageProvider({ getService, getPageObjects, updateBaseli const lastRow = await table.findByCssSelector('tr:last-child'); const fromCell = await lastRow.findByCssSelector('td:first-child input'); await fromCell.clearValue(); - await fromCell.type(`${from}`); + await fromCell.type(`${from}`, { charByChar: true }); const toCell = await lastRow.findByCssSelector('td:nth-child(2) input'); await toCell.clearValue(); - await toCell.type(`${to}`); + await toCell.type(`${to}`, { charByChar: true }); } async clickYAxisOptions(axisId) { diff --git a/test/functional/services/find.ts b/test/functional/services/find.ts index 40fc2f33cdc3..3c9757439818 100644 --- a/test/functional/services/find.ts +++ b/test/functional/services/find.ts @@ -67,6 +67,14 @@ export async function FindProvider({ getService }: FtrProviderContext) { return wrap(await driver.wait(until.elementLocated(By.css(selector)), timeout)); } + public async byXPath( + selector: string, + timeout: number = defaultFindTimeout + ): Promise { + log.debug(`Find.byXPath('${selector}') with timeout=${timeout}`); + return wrap(await driver.wait(until.elementLocated(By.xpath(selector)), timeout)); + } + public async byClassName( selector: string, timeout: number = defaultFindTimeout diff --git a/test/functional/services/test_subjects.ts b/test/functional/services/test_subjects.ts index 63b0d4763d58..b88828c44524 100644 --- a/test/functional/services/test_subjects.ts +++ b/test/functional/services/test_subjects.ts @@ -93,7 +93,7 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) { log.debug(`TestSubjects.doubleClick(${selector})`); const element = await this.find(selector, timeout); await element.moveMouseTo(); - await browser.doubleClick(); + await browser.doubleClick(element); }); } diff --git a/x-pack/test/functional/apps/canvas/feature_controls/canvas_security.ts b/x-pack/test/functional/apps/canvas/feature_controls/canvas_security.ts index e1591b943327..d830d19c3bc4 100644 --- a/x-pack/test/functional/apps/canvas/feature_controls/canvas_security.ts +++ b/x-pack/test/functional/apps/canvas/feature_controls/canvas_security.ts @@ -11,7 +11,6 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const esArchiver = getService('esArchiver'); const security = getService('security'); const PageObjects = getPageObjects(['common', 'canvas', 'security', 'spaceSelector']); - const find = getService('find'); const appsMenu = getService('appsMenu'); const globalNav = getService('globalNav'); @@ -222,15 +221,12 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa await security.user.delete('no_canvas_privileges_user'); }); - const getMessageText = async () => - await (await find.byCssSelector('body>pre')).getVisibleText(); - it(`returns a 404`, async () => { await PageObjects.common.navigateToActualUrl('canvas', '', { ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, @@ -245,7 +241,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/apps/canvas/feature_controls/canvas_spaces.ts b/x-pack/test/functional/apps/canvas/feature_controls/canvas_spaces.ts index eba2a5c507c9..63959b545dc3 100644 --- a/x-pack/test/functional/apps/canvas/feature_controls/canvas_spaces.ts +++ b/x-pack/test/functional/apps/canvas/feature_controls/canvas_spaces.ts @@ -12,7 +12,6 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const esArchiver = getService('esArchiver'); const spacesService: SpacesService = getService('spaces'); const PageObjects = getPageObjects(['common', 'canvas', 'security', 'spaceSelector']); - const find = getService('find'); const appsMenu = getService('appsMenu'); describe('spaces feature controls', () => { @@ -80,9 +79,6 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa }); describe('space with Canvas disabled', () => { - const getMessageText = async () => - await (await find.byCssSelector('body>pre')).getVisibleText(); - before(async () => { // we need to load the following in every situation as deleting // a space deletes all of the associated saved objects @@ -116,7 +112,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, @@ -136,7 +132,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa shouldLoginIfPrompted: false, } ); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/apps/maps/feature_controls/maps_security.ts b/x-pack/test/functional/apps/maps/feature_controls/maps_security.ts index 42afbfc19b2c..65532c0f7786 100644 --- a/x-pack/test/functional/apps/maps/feature_controls/maps_security.ts +++ b/x-pack/test/functional/apps/maps/feature_controls/maps_security.ts @@ -13,11 +13,8 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const PageObjects = getPageObjects(['common', 'settings', 'security', 'maps']); const appsMenu = getService('appsMenu'); const testSubjects = getService('testSubjects'); - const find = getService('find'); const globalNav = getService('globalNav'); - const getMessageText = async () => await (await find.byCssSelector('body>pre')).getVisibleText(); - describe('security feature controls', () => { before(async () => { await esArchiver.loadIfNeeded('maps/data'); @@ -207,7 +204,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/apps/maps/feature_controls/maps_spaces.ts b/x-pack/test/functional/apps/maps/feature_controls/maps_spaces.ts index d7c8f4b646ad..6a0f7cb4c206 100644 --- a/x-pack/test/functional/apps/maps/feature_controls/maps_spaces.ts +++ b/x-pack/test/functional/apps/maps/feature_controls/maps_spaces.ts @@ -13,9 +13,6 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const spacesService: SpacesService = getService('spaces'); const PageObjects = getPageObjects(['common', 'maps', 'security']); const appsMenu = getService('appsMenu'); - const find = getService('find'); - - const getMessageText = async () => await (await find.byCssSelector('body>pre')).getVisibleText(); describe('spaces feature controls', () => { before(async () => { @@ -90,7 +87,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/apps/timelion/feature_controls/timelion_security.ts b/x-pack/test/functional/apps/timelion/feature_controls/timelion_security.ts index f6109cfa5a4e..77d50037ce98 100644 --- a/x-pack/test/functional/apps/timelion/feature_controls/timelion_security.ts +++ b/x-pack/test/functional/apps/timelion/feature_controls/timelion_security.ts @@ -11,7 +11,6 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const esArchiver = getService('esArchiver'); const security = getService('security'); const PageObjects = getPageObjects(['common', 'timelion', 'header', 'security', 'spaceSelector']); - const find = getService('find'); const appsMenu = getService('appsMenu'); const globalNav = getService('globalNav'); @@ -170,15 +169,12 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa await security.user.delete('no_timelion_privileges_user'); }); - const getMessageText = async () => - await (await find.byCssSelector('body>pre')).getVisibleText(); - it(`returns a 404`, async () => { await PageObjects.common.navigateToActualUrl('timelion', '', { ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/apps/timelion/feature_controls/timelion_spaces.ts b/x-pack/test/functional/apps/timelion/feature_controls/timelion_spaces.ts index 68a3000a0c23..3871a7d5142d 100644 --- a/x-pack/test/functional/apps/timelion/feature_controls/timelion_spaces.ts +++ b/x-pack/test/functional/apps/timelion/feature_controls/timelion_spaces.ts @@ -12,11 +12,8 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa const esArchiver = getService('esArchiver'); const spacesService: SpacesService = getService('spaces'); const PageObjects = getPageObjects(['common', 'timelion', 'security', 'spaceSelector']); - const find = getService('find'); const appsMenu = getService('appsMenu'); - const getMessageText = async () => await (await find.byCssSelector('body>pre')).getVisibleText(); - describe('timelion', () => { before(async () => { await esArchiver.loadIfNeeded('logstash_functional'); @@ -89,7 +86,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, @@ -106,7 +103,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, @@ -123,7 +120,7 @@ export default function({ getPageObjects, getService }: KibanaFunctionalTestDefa shouldLoginIfPrompted: false, }); - const messageText = await getMessageText(); + const messageText = await PageObjects.common.getBodyText(); expect(messageText).to.eql( JSON.stringify({ statusCode: 404, diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js index 5b48680a94e1..4d2289284b47 100644 --- a/x-pack/test/functional/page_objects/security_page.js +++ b/x-pack/test/functional/page_objects/security_page.js @@ -28,6 +28,7 @@ export function SecurityPageProvider({ getService, getPageObjects }) { const expectSpaceSelector = options.expectSpaceSelector || false; const expectSuccess = options.expectSuccess; const expectForbidden = options.expectForbidden || false; + const rawDataTabLocator = 'a[id=rawdata-tab]'; await PageObjects.common.navigateToApp('login'); await testSubjects.setValue('loginUsername', username); @@ -39,6 +40,10 @@ export function SecurityPageProvider({ getService, getPageObjects }) { await retry.try(() => testSubjects.find('kibanaSpaceSelector')); log.debug(`Finished login process, landed on space selector. currentUrl = ${await browser.getCurrentUrl()}`); } else if (expectForbidden) { + if (await find.existsByCssSelector(rawDataTabLocator)) { + // Firefox has 3 tabs and requires navigation to see Raw output + await find.clickByCssSelector(rawDataTabLocator); + } await retry.try(async () => { await PageObjects.error.expectForbidden(); });