From 68e36ecb872150a5020e622b7f2499953069527f Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 11 Apr 2018 16:48:42 +0200 Subject: [PATCH] more wait calls --- .../src/areas/activitybar/activityBar.ts | 2 +- test/smoke/src/areas/explorer/explorer.ts | 4 +-- .../src/areas/extensions/extensions.test.ts | 8 ++---- test/smoke/src/areas/extensions/extensions.ts | 1 - .../src/areas/multiroot/multiroot.test.ts | 4 +-- .../src/areas/preferences/preferences.test.ts | 6 ++--- test/smoke/src/areas/statusbar/statusbar.ts | 4 +-- .../areas/workbench/data-migration.test.ts | 27 +++++-------------- .../src/areas/workbench/localization.test.ts | 17 ++++-------- test/smoke/src/areas/workbench/viewlet.ts | 8 +++--- test/smoke/src/main.ts | 19 +++++-------- test/smoke/src/vscode/code.ts | 9 +++---- 12 files changed, 35 insertions(+), 74 deletions(-) diff --git a/test/smoke/src/areas/activitybar/activityBar.ts b/test/smoke/src/areas/activitybar/activityBar.ts index 22d43a8f8c9..a2acb1ac44d 100644 --- a/test/smoke/src/areas/activitybar/activityBar.ts +++ b/test/smoke/src/areas/activitybar/activityBar.ts @@ -14,7 +14,7 @@ export class ActivityBar { constructor(private code: Code) { } - async getActivityBar(position: ActivityBarPosition): Promise { + async waitForActivityBar(position: ActivityBarPosition): Promise { let positionClass: string; if (position === ActivityBarPosition.LEFT) { diff --git a/test/smoke/src/areas/explorer/explorer.ts b/test/smoke/src/areas/explorer/explorer.ts index 15dc32668ee..ef9231393ef 100644 --- a/test/smoke/src/areas/explorer/explorer.ts +++ b/test/smoke/src/areas/explorer/explorer.ts @@ -21,8 +21,8 @@ export class Explorer extends Viewlet { return this.commands.runCommand('workbench.view.explorer'); } - getOpenEditorsViewTitle(): Promise { - return this.code.waitForTextContent(Explorer.OPEN_EDITORS_VIEW); + async waitForOpenEditorsViewTitle(fn: (title: string) => boolean): Promise { + await this.code.waitForTextContent(Explorer.OPEN_EDITORS_VIEW, undefined, fn); } async openFile(fileName: string): Promise { diff --git a/test/smoke/src/areas/extensions/extensions.test.ts b/test/smoke/src/areas/extensions/extensions.test.ts index 2a5b2f89fab..ca3cbc1774f 100644 --- a/test/smoke/src/areas/extensions/extensions.test.ts +++ b/test/smoke/src/areas/extensions/extensions.test.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; import { Application, Quality } from '../../application'; export function setup() { @@ -19,15 +18,12 @@ export function setup() { const extensionName = 'vscode-smoketest-check'; await app.workbench.extensions.openExtensionsViewlet(); - const installed = await app.workbench.extensions.installExtension(extensionName); - assert.ok(installed); + await app.workbench.extensions.installExtension(extensionName); await app.reload(); await app.workbench.extensions.waitForExtensionsViewlet(); await app.workbench.runCommand('Smoke Test Check'); - - const statusbarText = await app.workbench.statusbar.getStatusbarTextByTitle('smoke test'); - assert.equal(statusbarText, 'VS Code Smoke Test Check'); + await app.workbench.statusbar.waitForStatusbarText('smoke test', 'VS Code Smoke Test Check'); }); }); } \ No newline at end of file diff --git a/test/smoke/src/areas/extensions/extensions.ts b/test/smoke/src/areas/extensions/extensions.ts index 386e521e5f8..017c39d7420 100644 --- a/test/smoke/src/areas/extensions/extensions.ts +++ b/test/smoke/src/areas/extensions/extensions.ts @@ -32,7 +32,6 @@ export class Extensions extends Viewlet { async installExtension(name: string): Promise { await this.searchForExtension(name); - await this.code.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[aria-label="${name}"] .extension li[class='action-item'] .extension-action.install`); await this.code.waitForElement(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[aria-label="${name}"] .extension li[class='action-item'] .extension-action.reload`); } diff --git a/test/smoke/src/areas/multiroot/multiroot.test.ts b/test/smoke/src/areas/multiroot/multiroot.test.ts index 5b479677556..86449f54858 100644 --- a/test/smoke/src/areas/multiroot/multiroot.test.ts +++ b/test/smoke/src/areas/multiroot/multiroot.test.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; import { Application } from '../../application'; export function setup() { @@ -27,8 +26,7 @@ export function setup() { it('shows workspace name in title', async function () { const app = this.app as Application; - const title = await app.code.getTitle(); - assert.ok(title.indexOf('smoketest (Workspace)') >= 0); + await app.code.waitForTitle(title => /smoketest \(Workspace\)/i.test(title)); }); }); } \ No newline at end of file diff --git a/test/smoke/src/areas/preferences/preferences.test.ts b/test/smoke/src/areas/preferences/preferences.test.ts index ecca6a44167..1b2bbbec548 100644 --- a/test/smoke/src/areas/preferences/preferences.test.ts +++ b/test/smoke/src/areas/preferences/preferences.test.ts @@ -3,8 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; - import { Application } from '../../application'; import { ActivityBarPosition } from '../activitybar/activityBar'; @@ -23,12 +21,12 @@ export function setup() { it(`changes 'workbench.action.toggleSidebarPosition' command key binding and verifies it`, async function () { const app = this.app as Application; - assert.ok(await app.workbench.activitybar.getActivityBar(ActivityBarPosition.LEFT), 'Activity bar should be positioned on the left.'); + await app.workbench.activitybar.waitForActivityBar(ActivityBarPosition.LEFT); await app.workbench.keybindingsEditor.updateKeybinding('workbench.action.toggleSidebarPosition', 'ctrl+u', 'Control+U'); await app.code.dispatchKeybinding('ctrl+u'); - assert.ok(await app.workbench.activitybar.getActivityBar(ActivityBarPosition.RIGHT), 'Activity bar was not moved to right after toggling its position.'); + await app.workbench.activitybar.waitForActivityBar(ActivityBarPosition.RIGHT); }); after(async function () { diff --git a/test/smoke/src/areas/statusbar/statusbar.ts b/test/smoke/src/areas/statusbar/statusbar.ts index e4b8237f49b..dd3392a5a9c 100644 --- a/test/smoke/src/areas/statusbar/statusbar.ts +++ b/test/smoke/src/areas/statusbar/statusbar.ts @@ -37,8 +37,8 @@ export class StatusBar { return this.code.waitForTextContent(this.getSelector(StatusBarElement.EOL_STATUS), eol); } - async getStatusbarTextByTitle(title: string): Promise { - return await this.code.waitForTextContent(`${this.mainSelector} span[title="smoke test"]`); + async waitForStatusbarText(title: string, text: string): Promise { + await this.code.waitForTextContent(`${this.mainSelector} span[title="${title}"]`, text); } private getSelector(element: StatusBarElement): string { diff --git a/test/smoke/src/areas/workbench/data-migration.test.ts b/test/smoke/src/areas/workbench/data-migration.test.ts index 510cea17736..8fa282fd061 100644 --- a/test/smoke/src/areas/workbench/data-migration.test.ts +++ b/test/smoke/src/areas/workbench/data-migration.test.ts @@ -3,13 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; - import { Application, Quality } from '../../application'; import * as rimraf from 'rimraf'; export interface ICreateAppFn { - (quality: Quality): Application | null; + (quality: Quality): Application; } export function setup(userDataDir: string, createApp: ICreateAppFn) { @@ -40,14 +38,9 @@ export function setup(userDataDir: string, createApp: ICreateAppFn) { // Checking latest version for the restored state const app = createApp(Quality.Insiders); - if (!app) { - return assert(false); - } - await app.start(false); - assert.ok(await app.workbench.editors.waitForActiveTab('Untitled-1', true), `Untitled-1 tab is not present after migration.`); - + await app.workbench.editors.waitForActiveTab('Untitled-1', true); await app.workbench.editor.waitForEditorContents('Untitled-1', c => c.indexOf(textToType) > -1); await app.stop(); @@ -76,13 +69,9 @@ export function setup(userDataDir: string, createApp: ICreateAppFn) { // Checking latest version for the restored state const app = createApp(Quality.Insiders); - if (!app) { - return assert(false); - } - await app.start(false); - assert.ok(await app.workbench.editors.waitForActiveTab(fileName), `dirty file tab is not present after migration.`); + await app.workbench.editors.waitForActiveTab(fileName); await app.workbench.editor.waitForEditorContents(fileName, c => c.indexOf(textPart) > -1); await app.stop(); @@ -109,15 +98,11 @@ export function setup(userDataDir: string, createApp: ICreateAppFn) { const app = createApp(Quality.Insiders); - if (!app) { - return assert(false); - } - await app.start(false); - assert.ok(await app.workbench.editors.waitForTab(fileName1), `${fileName1} tab was not restored after migration.`); - assert.ok(await app.workbench.editors.waitForTab(fileName2), `${fileName2} tab was not restored after migration.`); - assert.ok(await app.workbench.editors.waitForTab(fileName3), `${fileName3} tab was not restored after migration.`); + await app.workbench.editors.waitForTab(fileName1); + await app.workbench.editors.waitForTab(fileName2); + await app.workbench.editors.waitForTab(fileName3); await app.stop(); }); diff --git a/test/smoke/src/areas/workbench/localization.test.ts b/test/smoke/src/areas/workbench/localization.test.ts index e3cc585758e..ea7a25bf8cf 100644 --- a/test/smoke/src/areas/workbench/localization.test.ts +++ b/test/smoke/src/areas/workbench/localization.test.ts @@ -3,8 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; - import { Application, Quality } from '../../application'; export function setup() { @@ -27,24 +25,19 @@ export function setup() { return; } - let text = await app.workbench.explorer.getOpenEditorsViewTitle(); - assert(/geƶffnete editoren/i.test(text)); + await app.workbench.explorer.waitForOpenEditorsViewTitle(title => /geƶffnete editoren/i.test(title)); await app.workbench.search.openSearchViewlet(); - text = await app.workbench.search.getTitle(); - assert(/suchen/i.test(text)); + await app.workbench.search.waitForTitle(title => /suchen/i.test(title)); await app.workbench.scm.openSCMViewlet(); - text = await app.workbench.scm.getTitle(); - assert(/quellcodeverwaltung/i.test(text)); + await app.workbench.scm.waitForTitle(title => /quellcodeverwaltung/i.test(title)); await app.workbench.debug.openDebugViewlet(); - text = await app.workbench.debug.getTitle(); - assert(/debuggen/i.test(text)); + await app.workbench.debug.waitForTitle(title => /debuggen/i.test(title)); await app.workbench.extensions.openExtensionsViewlet(); - text = await app.workbench.extensions.getTitle(); - assert(/erweiterungen/i.test(text)); + await app.workbench.extensions.waitForTitle(title => /erweiterungen/i.test(title)); }); }); } \ No newline at end of file diff --git a/test/smoke/src/areas/workbench/viewlet.ts b/test/smoke/src/areas/workbench/viewlet.ts index 82978b7770d..2293752b705 100644 --- a/test/smoke/src/areas/workbench/viewlet.ts +++ b/test/smoke/src/areas/workbench/viewlet.ts @@ -9,11 +9,9 @@ import { Code } from '../../vscode/code'; export abstract class Viewlet { - constructor(protected code: Code) { - // noop - } + constructor(protected code: Code) { } - async getTitle(): Promise { - return this.code.waitForTextContent('.monaco-workbench-container .part.sidebar > .title > .title-label > span'); + async waitForTitle(fn: (title: string) => boolean): Promise { + await this.code.waitForTextContent('.monaco-workbench-container .part.sidebar > .title > .title-label > span', undefined, fn); } } \ No newline at end of file diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index a534d232691..63149f3e522 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -100,16 +100,16 @@ function getBuildElectronPath(root: string): string { } let testCodePath = opts.build; -let stableCodePath = opts['stable-build']; +// let stableCodePath = opts['stable-build']; let electronPath: string; -let stablePath: string; +// let stablePath: string; if (testCodePath) { electronPath = getBuildElectronPath(testCodePath); - if (stableCodePath) { - stablePath = getBuildElectronPath(stableCodePath); - } + // if (stableCodePath) { + // stablePath = getBuildElectronPath(stableCodePath); + // } } else { testCodePath = getDevElectronPath(); electronPath = testCodePath; @@ -228,13 +228,7 @@ async function setup(): Promise { console.log('*** Smoketest setup done!\n'); } -function createApp(quality: Quality): Application | null { - const path = quality === Quality.Stable ? stablePath : electronPath; - - if (!path) { - return null; - } - +function createApp(quality: Quality): Application { return new Application({ quality, codePath: opts.build, @@ -246,6 +240,7 @@ function createApp(quality: Quality): Application | null { verbose: opts.verbose }); } + before(async function () { // allow two minutes for setup this.timeout(2 * 60 * 1000); diff --git a/test/smoke/src/vscode/code.ts b/test/smoke/src/vscode/code.ts index d76a45c7d80..2821a060e7b 100644 --- a/test/smoke/src/vscode/code.ts +++ b/test/smoke/src/vscode/code.ts @@ -246,23 +246,22 @@ export class Code { return await this.waitFor(() => this.driver.getElements(windowId, selector).then(els => els[0]), accept, `element with selector ${selector}`); } - async waitForActiveElement(selector: string): Promise { + async waitForActiveElement(selector: string): Promise { if (this.verbose) { console.log('- waitForActiveElement:', selector); } const windowId = await this.getActiveWindowId(); - return await this.waitFor(() => this.driver.isActiveElement(windowId, selector), undefined, `wait for active element: ${selector}`); + await this.waitFor(() => this.driver.isActiveElement(windowId, selector), undefined, `wait for active element: ${selector}`); } - // TODO make into waitForTitle - async getTitle(): Promise { + async waitForTitle(fn: (title: string) => boolean): Promise { if (this.verbose) { console.log('- getTitle'); } const windowId = await this.getActiveWindowId(); - return await this.driver.getTitle(windowId); + await this.waitFor(() => this.driver.getTitle(windowId), fn, 'wait for title: ${}'); } // TODO make into waitForTypeInEditor -- GitLab