#191860 - retry if command is not found

This commit is contained in:
Sandeep Somavarapu 2023-09-06 09:36:50 +02:00
parent 3e6068253b
commit 7a0fecc0a7
No known key found for this signature in database
GPG key ID: DD41CAAC8081CC7D
4 changed files with 44 additions and 8 deletions

View file

@ -254,6 +254,10 @@ export class Code {
return this.driver.getLogs();
}
wait(millis: number): Promise<void> {
return new Promise((resolve, reject) => setTimeout(resolve, millis));
}
private async poll<T>(
fn: () => Promise<T>,
acceptFn: (result: T) => boolean,

View file

@ -171,15 +171,47 @@ export class QuickAccess {
}
async runCommand(commandId: string, keepOpen?: boolean): Promise<void> {
let retries = 0;
let error;
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);
while (true) {
// wait for best choice to be focused
await this.quickInput.waitForQuickInputElementFocused();
if (++retries > 5) {
throw error ?? new Error(`Command: ${commandId} Not found`);
}
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);
// wait for best choice to be focused
await this.quickInput.waitForQuickInputElementFocused();
// Retry for as long as the command not found
const text = await this.quickInput.waitForQuickInputElementText();
if (text === 'No matching commands') {
this.code.logger.log(`QuickAccess: No matching commands, will retry...`);
await this.quickInput.closeQuickInput();
await this.code.wait(1000);
continue;
}
try {
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
} catch (err) {
if (keepOpen) {
throw err;
} else {
error = err;
this.code.logger.log(`QuickAccess: Probably no matching commands, will retry...`);
await this.quickInput.closeQuickInput();
continue;
}
}
break;
}
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
}
async openQuickOutline(): Promise<void> {

View file

@ -7,7 +7,7 @@ import { Application, Logger } from '../../../../automation';
import { installAllHandlers } from '../../utils';
export function setup(logger: Logger) {
describe.skip('Extensions', () => {
describe('Extensions', () => {
// Shared before/after handling
installAllHandlers(logger);

View file

@ -8,7 +8,7 @@ import { installAllHandlers } from '../../utils';
export function setup(logger: Logger) {
describe.skip('Localization', () => {
describe('Localization', () => {
// Shared before/after handling
installAllHandlers(logger);