From f21e31acf26e18e76d32cfafb0cfae83f98bd7f5 Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Wed, 1 Nov 2023 14:45:32 +0100 Subject: [PATCH] [security_page] improve force logout (#170227) ## Summary Addressing `forceLogout` flakiness https://buildkite.com/elastic/appex-qa-serverless-kibana-ftr-tests/builds/370 ``` Error: timed out waiting for Waiting for logout to complete at onFailure (retry_for_truthy.ts:39:13) at retryForSuccess (retry_for_success.ts:59:13) at retryForTruthy (retry_for_truthy.ts:27:3) at RetryService.waitFor (retry.ts:59:5) at SecurityPageObject.forceLogout (security_page.ts:319:7) at Object.forceLogout (svl_common_page.ts:95:7) at Context. (view_case.ts:44:7) at Object.apply (wrap_function.js:73:16) ``` image Flaky-test-runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3839 200/200 --- .../functional/page_objects/security_page.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/x-pack/test/functional/page_objects/security_page.ts b/x-pack/test/functional/page_objects/security_page.ts index 5b0a9a679840a..bb127df565ccd 100644 --- a/x-pack/test/functional/page_objects/security_page.ts +++ b/x-pack/test/functional/page_objects/security_page.ts @@ -41,6 +41,8 @@ export class SecurityPageObject extends FtrService { private readonly monacoEditor = this.ctx.getService('monacoEditor'); private readonly es = this.ctx.getService('es'); + delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + public loginPage = Object.freeze({ login: async (username?: string, password?: string, options: LoginOptions = {}) => { if (!(await this.isLoginFormVisible())) { @@ -316,7 +318,7 @@ export class SecurityPageObject extends FtrService { await this.waitForLoginPage(); } else { this.log.debug('Waiting for logout to complete'); - await this.retry.waitFor('Waiting for logout to complete', async () => { + await this.retry.waitFor('logout to complete', async () => { // There are cases when browser/Kibana would like users to confirm that they want to navigate away from the // current page and lose the state (e.g. unsaved changes) via native alert dialog. const alert = await this.browser.getAlert(); @@ -324,12 +326,19 @@ export class SecurityPageObject extends FtrService { await alert.accept(); } + await this.retry.waitFor('URL redirects to finish', async () => { + const urlBefore = await this.browser.getCurrentUrl(); + await this.delay(1000); + const urlAfter = await this.browser.getCurrentUrl(); + return urlAfter === urlBefore; + }); + + const currentUrl = await this.browser.getCurrentUrl(); if (this.config.get('serverless')) { // Logout might trigger multiple redirects, but in the end we expect the Cloud login page - this.log.debug('Wait 5 sec for Cloud login page to be displayed'); - return await this.find.existsByDisplayedByCssSelector('.login-form-password', 5000); + return currentUrl.includes('/login') || currentUrl.includes('/projects'); } else { - return !(await this.browser.getCurrentUrl()).includes('/logout'); + return !currentUrl.includes('/logout'); } }); }