Merge pull request #192270 from microsoft/sandy081/dreadful-ferret

#191860 - retry if command is not found
This commit is contained in:
Sandeep Somavarapu
2023-09-06 11:59:04 +02:00
committed by GitHub
6 changed files with 36 additions and 14 deletions
+6 -2
View File
@@ -185,7 +185,7 @@ export class Code {
try {
process.kill(pid, 0); // throws an exception if the process doesn't exist anymore.
await new Promise(resolve => setTimeout(resolve, 500));
await this.wait(500);
} catch (error) {
done = true;
resolve();
@@ -254,6 +254,10 @@ export class Code {
return this.driver.getLogs();
}
wait(millis: number): Promise<void> {
return this.driver.wait(millis);
}
private async poll<T>(
fn: () => Promise<T>,
acceptFn: (result: T) => boolean,
@@ -285,7 +289,7 @@ export class Code {
lastError = Array.isArray(e.stack) ? e.stack.join(os.EOL) : e.stack;
}
await new Promise(resolve => setTimeout(resolve, retryInterval));
await this.wait(retryInterval);
trial++;
}
}
+3 -3
View File
@@ -157,7 +157,7 @@ export class PlaywrightDriver {
for (let i = 0; i < chords.length; i++) {
const chord = chords[i];
if (i > 0) {
await this.timeout(100);
await this.wait(100);
}
if (keybinding.startsWith('Alt') || keybinding.startsWith('Control') || keybinding.startsWith('Backspace')) {
@@ -179,7 +179,7 @@ export class PlaywrightDriver {
}
}
await this.timeout(100);
await this.wait(100);
}
async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined) {
@@ -235,7 +235,7 @@ export class PlaywrightDriver {
return this.page.evaluate(pageFunction, [await this.getDriverHandle()]);
}
private timeout(ms: number): Promise<void> {
wait(ms: number): Promise<void> {
return new Promise<void>(resolve => setTimeout(resolve, ms));
}
+24 -6
View File
@@ -171,15 +171,33 @@ export class QuickAccess {
}
async runCommand(commandId: string, keepOpen?: boolean): Promise<void> {
let retries = 0;
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);
while (++retries < 5) {
// wait for best choice to be focused
await this.quickInput.waitForQuickInputElementFocused();
// 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;
}
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
return;
}
throw new Error(`Command: ${commandId} Not found`);
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
}
async openQuickOutline(): Promise<void> {
+1 -1
View File
@@ -99,7 +99,7 @@ export class Terminal {
// after 2 seconds.
await Promise.race([
this.code.waitForElements(Selector.Xterm, true, e => e.length === 0),
new Promise<void>(r => setTimeout(r, 2000))
this.code.wait(2000)
]);
break;
}
@@ -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);
@@ -8,7 +8,7 @@ import { installAllHandlers } from '../../utils';
export function setup(logger: Logger) {
describe.skip('Localization', () => {
describe('Localization', () => {
// Shared before/after handling
installAllHandlers(logger);