Improve localization smoke test

This commit is contained in:
Dirk Baeumer 2021-06-21 13:54:16 +02:00
parent 78946a0204
commit 1f2a6cc331
No known key found for this signature in database
GPG key ID: DD95715335E91385
12 changed files with 89 additions and 21 deletions

View file

@ -5,7 +5,8 @@
import { getTopLeftOffset, getClientArea } from 'vs/base/browser/dom';
import { coalesce } from 'vs/base/common/arrays';
import { IElement, IWindowDriver } from 'vs/platform/driver/common/driver';
import { IElement, ILocalizedStrings, IWindowDriver } from 'vs/platform/driver/common/driver';
import localizedStrings from 'vs/platform/localizations/common/localizedStrings';
function serializeElement(element: Element, recursive: boolean): IElement {
const attributes = Object.create(null);
@ -161,6 +162,14 @@ export abstract class BaseWindowDriver implements IWindowDriver {
xterm._core._coreService.triggerDataEvent(text);
}
getLocalizedStrings(): Promise<ILocalizedStrings> {
return Promise.resolve({
open: localizedStrings.open,
close: localizedStrings.close,
find: localizedStrings.find
});
}
protected async _getElementXY(selector: string, offset?: { x: number, y: number }): Promise<{ x: number; y: number; }> {
const element = document.querySelector(selector);

View file

@ -18,6 +18,12 @@ export interface IElement {
left: number;
}
export interface ILocalizedStrings {
open: string;
close: string;
find: string;
}
export interface IDriver {
readonly _serviceBrand: undefined;
@ -36,6 +42,7 @@ export interface IDriver {
typeInEditor(windowId: number, selector: string, text: string): Promise<void>;
getTerminalBuffer(windowId: number, selector: string): Promise<string[]>;
writeInTerminal(windowId: number, selector: string, text: string): Promise<void>;
getLocalizedStrings(windowId: number): Promise<ILocalizedStrings>
}
//*END
@ -53,6 +60,7 @@ export interface IWindowDriver {
typeInEditor(selector: string, text: string): Promise<void>;
getTerminalBuffer(selector: string): Promise<string[]>;
writeInTerminal(selector: string, text: string): Promise<void>;
getLocalizedStrings(): Promise<ILocalizedStrings>
}
export interface IDriverOptions {

View file

@ -5,7 +5,7 @@
import { Event } from 'vs/base/common/event';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { IDriverOptions, IElement, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { IDriverOptions, IElement, ILocalizedStrings as ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
export class WindowDriverChannel implements IServerChannel {
@ -27,6 +27,7 @@ export class WindowDriverChannel implements IServerChannel {
case 'typeInEditor': return this.driver.typeInEditor(arg[0], arg[1]);
case 'getTerminalBuffer': return this.driver.getTerminalBuffer(arg);
case 'writeInTerminal': return this.driver.writeInTerminal(arg[0], arg[1]);
case 'getLocalizedStrings': return this.driver.getLocalizedStrings();
}
throw new Error(`Call not found: ${command}`);
@ -78,6 +79,10 @@ export class WindowDriverChannelClient implements IWindowDriver {
writeInTerminal(selector: string, text: string): Promise<void> {
return this.channel.call('writeInTerminal', [selector, text]);
}
getLocalizedStrings(): Promise<ILocalizedStrings> {
return this.channel.call('getLocalizedStrings');
}
}
export class WindowDriverRegistryChannelClient implements IWindowDriverRegistry {

View file

@ -18,7 +18,7 @@ import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/e
import { ScanCodeBinding } from 'vs/base/common/scanCode';
import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { timeout } from 'vs/base/common/async';
import { IDriver, IDriverOptions, IElement, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { IDriver, IDriverOptions, IElement, ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
@ -189,6 +189,11 @@ export class Driver implements IDriver, IWindowDriverRegistry {
await windowDriver.writeInTerminal(selector, text);
}
async getLocalizedStrings(windowId: number): Promise<ILocalizedStrings> {
const windowDriver = await this.getWindowDriver(windowId);
return await windowDriver.getLocalizedStrings();
}
private async getWindowDriver(windowId: number): Promise<IWindowDriver> {
await this.whenUnfrozen(windowId);

View file

@ -7,7 +7,7 @@ import { Client } from 'vs/base/parts/ipc/common/ipc.net';
import { connect as connectNet } from 'vs/base/parts/ipc/node/ipc.net';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { Event } from 'vs/base/common/event';
import { IDriver, IElement, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { IDriver, IElement, IWindowDriverRegistry, ILocalizedStrings } from 'vs/platform/driver/common/driver';
export class DriverChannel implements IServerChannel {
@ -34,6 +34,7 @@ export class DriverChannel implements IServerChannel {
case 'typeInEditor': return this.driver.typeInEditor(arg[0], arg[1], arg[2]);
case 'getTerminalBuffer': return this.driver.getTerminalBuffer(arg[0], arg[1]);
case 'writeInTerminal': return this.driver.writeInTerminal(arg[0], arg[1], arg[2]);
case 'getLocalizedStrings': return this.driver.getLocalizedStrings(arg);
}
throw new Error(`Call not found: ${command}`);
@ -105,6 +106,10 @@ export class DriverChannelClient implements IDriver {
writeInTerminal(windowId: number, selector: string, text: string): Promise<void> {
return this.channel.call('writeInTerminal', [windowId, selector, text]);
}
getLocalizedStrings(windowId: number): Promise<ILocalizedStrings> {
return this.channel.call('getLocalizedStrings', windowId);
}
}
export class WindowDriverRegistryChannel implements IServerChannel {

View file

@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
/**
* These are some predefined strings that we test during smoke testing that they are localized
* correctly. Don't change these strings!!
*/
const open: string = nls.localize('open', 'open');
const close: string = nls.localize('close', 'close');
const find: string = nls.localize('find', 'find');
export default {
open: open,
close: close,
find: find
};

View file

@ -9,7 +9,7 @@ import * as os from 'os';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import { tmpName } from 'tmp';
import { IDriver, connect as connectElectronDriver, IDisposable, IElement, Thenable } from './driver';
import { IDriver, connect as connectElectronDriver, IDisposable, IElement, Thenable, ILocalizedStrings } from './driver';
import { connect as connectPlaywrightDriver, launch } from './playwrightDriver';
import { Logger } from './logger';
import { ncp } from 'ncp';
@ -360,6 +360,11 @@ export class Code {
await poll(() => this.driver.writeInTerminal(windowId, selector, value), () => true, `writeInTerminal '${selector}'`);
}
async getLocalizedStrings(): Promise<ILocalizedStrings> {
const windowId = await this.getActiveWindowId();
return await this.driver.getLocalizedStrings(windowId);
}
private async getActiveWindowId(): Promise<number> {
if (typeof this._activeWindowId !== 'number') {
const windows = await this.driver.getWindowIds();

View file

@ -23,5 +23,6 @@ export * from './settings';
export * from './statusbar';
export * from './terminal';
export * from './viewlet';
export * from './localization';
export * from './workbench';
export * from './driver';

View file

@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Code } from './code';
import { ILocalizedStrings } from './driver';
export class Localization {
constructor(private code: Code) { }
async getLocalizedStrings(): Promise<ILocalizedStrings> {
return this.code.getLocalizedStrings();
}
}

View file

@ -81,7 +81,8 @@ function buildDriver(browser: playwright.Browser, page: playwright.Page): IDrive
getElementXY: (windowId, selector, xoffset?, yoffset?) => page.evaluate(`window.driver.getElementXY('${selector}', ${xoffset}, ${yoffset})`),
typeInEditor: (windowId, selector, text) => page.evaluate(`window.driver.typeInEditor('${selector}', '${text}')`),
getTerminalBuffer: (windowId, selector) => page.evaluate(`window.driver.getTerminalBuffer('${selector}')`),
writeInTerminal: (windowId, selector, text) => page.evaluate(`window.driver.writeInTerminal('${selector}', '${text}')`)
writeInTerminal: (windowId, selector, text) => page.evaluate(`window.driver.writeInTerminal('${selector}', '${text}')`),
getLocalizedStrings: (windowId) => page.evaluate(`window.driver.getLocalizedStrings()`)
};
return driver;
}

View file

@ -20,6 +20,7 @@ import { Editors } from './editors';
import { Code } from './code';
import { Terminal } from './terminal';
import { Notebook } from './notebook';
import { Localization } from './localization';
export interface Commands {
runCommand(command: string): Promise<any>;
@ -43,6 +44,7 @@ export class Workbench {
readonly keybindingsEditor: KeybindingsEditor;
readonly terminal: Terminal;
readonly notebook: Notebook;
readonly localization: Localization;
constructor(code: Code, userDataPath: string) {
this.editors = new Editors(code);
@ -61,5 +63,6 @@ export class Workbench {
this.keybindingsEditor = new KeybindingsEditor(code);
this.terminal = new Terminal(code, this.quickaccess);
this.notebook = new Notebook(this.quickaccess, code);
this.localization = new Localization(code);
}
}

View file

@ -30,25 +30,15 @@ export function setup(opts: minimist.ParsedArgs) {
it(`starts with 'DE' locale and verifies title and viewlets text is in German`, async function () {
const app = this.app as Application;
const result = await app.workbench.localization.getLocalizedStrings();
if (app.quality === Quality.Dev || app.remote) {
this.skip();
if (result.open !== 'open' || result.close !== 'close' || result.find !== 'find') {
throw new Error(`Received localized strings: ${JSON.stringify(result, undefined, 0)}`);
}
return;
}
// await app.workbench.explorer.waitForOpenEditorsViewTitle(title => /geöffnete editoren/i.test(title));
await app.workbench.search.openSearchViewlet();
await app.workbench.search.waitForTitle(title => /suchen/i.test(title));
// await app.workbench.scm.openSCMViewlet();
// await app.workbench.scm.waitForTitle(title => /quellcodeverwaltung/i.test(title));
// See https://github.com/microsoft/vscode/issues/93462
// await app.workbench.debug.openDebugViewlet();
// await app.workbench.debug.waitForTitle(title => /starten/i.test(title));
// await app.workbench.extensions.openExtensionsViewlet();
// await app.workbench.extensions.waitForTitle(title => /extensions/i.test(title));
// As soon as strings are translated in the next round we can check for german as well.
});
});
}