Fix extensions smoke test (#195264)

#193046
- add waitForWorkbenchRestored method to driver
- move driver to workbench
- wait for workbench to restore if command is not found
This commit is contained in:
Sandeep Somavarapu 2023-10-10 20:11:30 +02:00 committed by GitHub
parent 7a10a0e89b
commit 2f51809ca3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 25 deletions

View file

@ -17,7 +17,6 @@ import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IDialogService, IPromptButton } from 'vs/platform/dialogs/common/dialogs';
import { registerWindowDriver } from 'vs/platform/driver/browser/driver';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ILabelService } from 'vs/platform/label/common/label';
import { IOpenerService, matchesScheme } from 'vs/platform/opener/common/opener';
@ -27,6 +26,7 @@ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/la
import { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { registerWindowDriver } from 'vs/workbench/services/driver/browser/driver';
export class BrowserWindow extends Disposable {

View file

@ -62,7 +62,6 @@ import { whenEditorClosed } from 'vs/workbench/browser/editor';
import { ISharedProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { registerWindowDriver } from 'vs/platform/driver/electron-sandbox/driver';
import { ILabelService } from 'vs/platform/label/common/label';
import { dirname } from 'vs/base/common/resources';
import { IBannerService } from 'vs/workbench/services/banner/browser/bannerService';
@ -70,6 +69,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { IUtilityProcessWorkerWorkbenchService } from 'vs/workbench/services/utilityProcess/electron-sandbox/utilityProcessWorkerWorkbenchService';
import { registerWindowDriver } from 'vs/workbench/services/driver/electron-sandbox/driver';
export class NativeWindow extends Disposable {

View file

@ -6,18 +6,20 @@
import { getClientArea, getTopLeftOffset } from 'vs/base/browser/dom';
import { coalesce } from 'vs/base/common/arrays';
import { language, locale } from 'vs/base/common/platform';
import { IElement, ILocaleInfo, ILocalizedStrings, ILogFile, IWindowDriver } from 'vs/platform/driver/common/driver';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import localizedStrings from 'vs/platform/languagePacks/common/localizedStrings';
import { getLogs } from 'vs/platform/log/browser/log';
import { ILogFile, getLogs } from 'vs/platform/log/browser/log';
import { IWindowDriver, IElement, ILocaleInfo, ILocalizedStrings } from 'vs/workbench/services/driver/common/driver';
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
export class BrowserWindowDriver implements IWindowDriver {
constructor(
@IFileService private readonly fileService: IFileService,
@IEnvironmentService private readonly environmentService: IEnvironmentService
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@ILifecycleService private readonly lifecycleService: ILifecycleService,
) {
}
@ -25,6 +27,10 @@ export class BrowserWindowDriver implements IWindowDriver {
return getLogs(this.fileService, this.environmentService);
}
whenWorkbenchRestored(): Promise<void> {
return this.lifecycleService.when(LifecyclePhase.Restored);
}
async setValue(selector: string, text: string): Promise<void> {
const element = document.querySelector(selector);
@ -211,6 +217,7 @@ export class BrowserWindowDriver implements IWindowDriver {
async exitApplication(): Promise<void> {
// No-op in web
}
}
export function registerWindowDriver(instantiationService: IInstantiationService): void {

View file

@ -43,6 +43,7 @@ export interface IWindowDriver {
getLocaleInfo(): Promise<ILocaleInfo>;
getLocalizedStrings(): Promise<ILocalizedStrings>;
getLogs(): Promise<ILogFile[]>;
whenWorkbenchRestored(): Promise<void>;
exitApplication(): Promise<void>;
}
//*END

View file

@ -3,10 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { BrowserWindowDriver } from 'vs/platform/driver/browser/driver';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { BrowserWindowDriver } from 'vs/workbench/services/driver/browser/driver';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
interface INativeWindowDriverHelper {
exitApplication(): Promise<void>;
@ -17,9 +18,10 @@ class NativeWindowDriver extends BrowserWindowDriver {
constructor(
private readonly helper: INativeWindowDriverHelper,
@IFileService fileService: IFileService,
@IEnvironmentService environmentService: IEnvironmentService
@IEnvironmentService environmentService: IEnvironmentService,
@ILifecycleService lifecycleService: ILifecycleService
) {
super(fileService, environmentService);
super(fileService, environmentService, lifecycleService);
}
override exitApplication(): Promise<void> {

View file

@ -242,6 +242,10 @@ export class Code {
await this.poll(() => this.driver.writeInTerminal(selector, value), () => true, `writeInTerminal '${selector}'`);
}
whenWorkbenchRestored(): Promise<void> {
return this.driver.whenWorkbenchRestored();
}
getLocaleInfo(): Promise<ILocaleInfo> {
return this.driver.getLocaleInfo();
}

View file

@ -239,6 +239,10 @@ export class PlaywrightDriver {
return new Promise<void>(resolve => setTimeout(resolve, ms));
}
whenWorkbenchRestored(): Promise<void> {
return this.evaluateWithDriver(([driver]) => driver.whenWorkbenchRestored());
}
private async getDriverHandle(): Promise<playwright.JSHandle<IWindowDriver>> {
return this.page.evaluateHandle('window.driver');
}

View file

@ -171,13 +171,10 @@ export class QuickAccess {
}
async runCommand(commandId: string, options?: { keepOpen?: boolean; exactLabelMatch?: boolean }): Promise<void> {
let retries = 0;
const keepOpen = options?.keepOpen;
const exactLabelMatch = options?.exactLabelMatch;
while (++retries < 5) {
const openCommandPalletteAndTypeCommand = async (): Promise<string> => {
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);
@ -185,22 +182,27 @@ export class QuickAccess {
await this.quickInput.waitForQuickInputElementFocused();
// Retry for as long as the command not found
const text = await this.quickInput.waitForQuickInputElementText();
return await this.quickInput.waitForQuickInputElementText();
};
let text = await openCommandPalletteAndTypeCommand();
if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
this.code.logger.log(`QuickAccess: No matching commands, will retry...`);
await this.quickInput.closeQuickInput();
// Wait for workbench to be restored
await this.code.whenWorkbenchRestored();
// Retry after workbench is restored
text = await openCommandPalletteAndTypeCommand();
if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
this.code.logger.log(`QuickAccess: No matching commands, will retry...`);
await this.quickInput.closeQuickInput();
await this.code.wait(1000);
continue;
throw new Error(`Command: ${commandId} Not found`);
}
// 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> {

View file

@ -10,7 +10,7 @@ const fs = require('fs');
const path = require('path');
const root = path.dirname(path.dirname(path.dirname(__dirname)));
const driverPath = path.join(root, 'src/vs/platform/driver/common/driver.ts');
const driverPath = path.join(root, 'src/vs/workbench/services/driver/common/driver.ts');
let contents = fs.readFileSync(driverPath, 'utf8');
contents = /\/\/\*START([\s\S]*)\/\/\*END/mi.exec(contents)[1].trim();