Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.12] [ftr] abort retry on invalid webdriver session (#174092) #174129

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ export async function retryForSuccess<T>(log: ToolingLog, options: Options<T>) {

const start = Date.now();
const retryDelay = 502;
const criticalWebDriverErrors = ['NoSuchSessionError', 'NoSuchWindowError'];
let lastError;

while (true) {
if (Date.now() - start > timeout) {
await onFailure(lastError);
throw new Error('expected onFailure() option to throw an error');
} else if (lastError && criticalWebDriverErrors.includes(lastError.name)) {
// Aborting retry since WebDriver session is invalid or browser window is closed
throw new Error('WebDriver session is invalid, retry was aborted');
} else if (lastError && onFailureBlock) {
const before = await runAttempt(onFailureBlock);
if ('error' in before) {
Expand Down
5 changes: 4 additions & 1 deletion test/common/services/security/test_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export class TestUser extends FtrService {
});

if (this.browser && this.testSubjects && !options?.skipBrowserRefresh) {
if (await this.testSubjects.exists('kibanaChrome', { allowHidden: true })) {
if (
(await this.browser.hasOpenWindow()) &&
(await this.testSubjects.exists('kibanaChrome', { allowHidden: true }))
) {
await this.browser.refresh();
// accept alert if it pops up
const alert = await this.browser.getAlert();
Expand Down
6 changes: 5 additions & 1 deletion test/functional/services/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { NoSuchSessionError } from 'selenium-webdriver/lib/error';
import { NoSuchSessionError, NoSuchWindowError } from 'selenium-webdriver/lib/error';
import { FtrProviderContext } from '../../ftr_provider_context';
import { initWebDriver, BrowserConfig } from './webdriver';
import { Browsers } from './browsers';
Expand Down Expand Up @@ -37,6 +37,10 @@ export async function RemoteProvider({ getService }: FtrProviderContext) {
// Avoid duplicating NoSuchSessionError error output on each hook
// https://developer.mozilla.org/en-US/docs/Web/WebDriver/Errors/InvalidSessionID
log.error('WebDriver session is no longer valid');
} else if (error instanceof NoSuchWindowError) {
// Avoid duplicating NoSuchWindowError error output on each hook
// https://developer.mozilla.org/en-US/docs/Web/WebDriver/Errors
log.error('Browser window is already closed');
} else {
throw error;
}
Expand Down
Loading