diff --git a/test/smoke/src/areas/git/git.test.ts b/test/smoke/src/areas/git/git.test.ts index 9bebc99a0fc..754789d8832 100644 --- a/test/smoke/src/areas/git/git.test.ts +++ b/test/smoke/src/areas/git/git.test.ts @@ -10,11 +10,8 @@ const DIFF_EDITOR_LINE_INSERT = '.monaco-diff-editor .editor.modified .line-inse const SYNC_STATUSBAR = 'div[id="workbench.parts.statusbar"] .statusbar-entry a[title$="Synchronize Changes"]'; describe('Git', () => { - let app: SpectronApplication; - before(() => { - app = new SpectronApplication(LATEST_PATH, '', 0, [WORKSPACE_PATH]); - return app.start(); - }); + let app: SpectronApplication = new SpectronApplication(LATEST_PATH, '', 0, [WORKSPACE_PATH]); + before(() => app.start()); after(() => app.stop()); it('reflects working tree changes', async function () { diff --git a/test/smoke/src/areas/integrated-terminal.ts b/test/smoke/src/areas/integrated-terminal.ts deleted file mode 100644 index 1ceb5a8ebeb..00000000000 --- a/test/smoke/src/areas/integrated-terminal.ts +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { SpectronApplication } from '../spectron/application'; -import { CommonActions } from './common'; - -export class IntegratedTerminal { - - public static terminalSelector = 'div[id="workbench.panel.terminal"]'; - public static terminalRowsSelector = 'div[id="workbench.panel.terminal"] .xterm-rows'; - - constructor(private spectron: SpectronApplication) { - // noop - } - - public async openTerminal(commonActions: CommonActions): Promise { - // Backquote dispatching does not work in OS X - if (process.platform === 'darwin') { - await commonActions.showCommands(); - await commonActions.type('Toggle Integrated Terminal'); - return commonActions.enter(); - } - - await this.spectron.command('workbench.action.terminal.toggleTerminal'); - - // If no terminal panel was opened, try triggering terminal from quick open - try { - await this.spectron.client.waitForHTML(IntegratedTerminal.terminalSelector); - } catch (e) { - await commonActions.openQuickOpen(); - await this.spectron.client.keys('>Toggle Integrated Terminal'); - await this.spectron.client.keys(['Enter', 'NULL']); - } - } - - public async commandOutputHas(result: string): Promise { - const rows = await this.spectron.client.waitForElements(`${IntegratedTerminal.terminalRowsSelector} div`); - for (let i = 0; i < rows.length; i++) { - let rowText; - try { - rowText = await this.spectron.client.getText(`${IntegratedTerminal.terminalRowsSelector}>:nth-child(${i + 1})`); - } catch (e) { - return Promise.reject(`Failed to obtain text from line ${i + 1} from the terminal.`); - } - if (rowText.trim() === result) { - return true; - } - } - - return false; - } -} \ No newline at end of file diff --git a/test/smoke/src/areas/statusbar/statusbar.ts b/test/smoke/src/areas/statusbar/statusbar.ts index af0fe719097..4e73dd78c7e 100644 --- a/test/smoke/src/areas/statusbar/statusbar.ts +++ b/test/smoke/src/areas/statusbar/statusbar.ts @@ -19,7 +19,6 @@ export enum StatusBarElement { export class StatusBar { - // private selectorsMap: Map; private readonly mainSelector = 'div[id="workbench.parts.statusbar"]'; constructor(private spectron: SpectronApplication) { diff --git a/test/smoke/src/areas/terminal/terminal.test.ts b/test/smoke/src/areas/terminal/terminal.test.ts new file mode 100644 index 00000000000..521e7a332e8 --- /dev/null +++ b/test/smoke/src/areas/terminal/terminal.test.ts @@ -0,0 +1,24 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as assert from 'assert'; +import { SpectronApplication, LATEST_PATH, WORKSPACE_PATH } from '../../spectron/application'; + +describe('Terminal', () => { + let app: SpectronApplication = new SpectronApplication(LATEST_PATH, '', 0, [WORKSPACE_PATH]); + before(() => app.start()); + after(() => app.stop()); + + it(`opens terminal, runs 'echo' and verifies the output`, async function () { + const expected = new Date().getTime().toString(); + await app.workbench.terminal.showTerminal(); + + const currentLine = await app.workbench.terminal.getCurrentLineNumber(); + await app.workbench.terminal.runCommand(`echo ${expected}`); + + const actual = await app.workbench.terminal.waitForText(currentLine + 1, text => !!text.trim()); + assert.equal(actual.trim(), expected); + }); +}); \ No newline at end of file diff --git a/test/smoke/src/areas/terminal/terminal.ts b/test/smoke/src/areas/terminal/terminal.ts new file mode 100644 index 00000000000..2814ae7059d --- /dev/null +++ b/test/smoke/src/areas/terminal/terminal.ts @@ -0,0 +1,75 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { SpectronApplication } from '../../spectron/application'; + +export class Terminal { + + static TERMINAL_SELECTOR = '.panel.integrated-terminal'; + static TERMINAL_ROWS_SELECTOR = `${Terminal.TERMINAL_SELECTOR} .xterm-rows > div`; + + constructor(private spectron: SpectronApplication) { + } + + public async showTerminal(): Promise { + if (!await this.isVisible()) { + await this.spectron.workbench.commandPallette.runCommand('Toggle Integrated Terminal'); + await this.spectron.client.waitForElement(Terminal.TERMINAL_SELECTOR); + await this.waitForText(1, text => text.trim().indexOf('vscode-smoketest-express git:(master)') !== -1); + } + } + + public async isVisible(): Promise { + const element = await this.spectron.client.element(Terminal.TERMINAL_SELECTOR); + return !!element; + } + + public async runCommand(commandText: string): Promise { + await this.spectron.type(commandText); + await this.spectron.client.keys(['Enter', 'NULL']); + } + + public async waitForText(line: number, fn: (text: string) => boolean): Promise { + return this.spectron.client.waitFor(async () => { + const terminalText = await this.getTerminalText(); + if (fn(terminalText[line - 1])) { + return terminalText[line - 1]; + } + return undefined; + }); + } + + public getCurrentLineNumber(): Promise { + return this.getTerminalText().then(text => text.length); + } + + private async getTerminalText(): Promise { + const linesText: string[] = await this.spectron.webclient.selectorExecute(Terminal.TERMINAL_ROWS_SELECTOR, + div => (Array.isArray(div) ? div : [div]) + .map(element => { + function getTextFromAll(spanElements: NodeList): string { + let text = ''; + for (let i = 0; i < spanElements.length; i++) { + text += getText(spanElements.item(i) as HTMLElement); + } + return text; + } + function getText(spanElement: HTMLElement): string { + if (spanElement.hasChildNodes()) { + return getTextFromAll(spanElement.childNodes); + } + return spanElement.textContent || ''; + } + return getTextFromAll(element.querySelectorAll('span')); + })); + let lastLineIndex = 0; + for (let index = 0; index < linesText.length; index++) { + if (linesText[index].trim()) { + lastLineIndex = index; + } + } + return linesText.slice(0, lastLineIndex + 1); + } +} \ No newline at end of file diff --git a/test/smoke/src/areas/workbench/workbench.ts b/test/smoke/src/areas/workbench/workbench.ts index 345d3e503af..c966e1131c3 100644 --- a/test/smoke/src/areas/workbench/workbench.ts +++ b/test/smoke/src/areas/workbench/workbench.ts @@ -18,6 +18,7 @@ import { StatusBar } from '../statusbar/statusbar'; import { Problems } from '../problems/problems'; import { SettingsEditor } from '../preferences/settings'; import { KeybindingsEditor } from '../preferences/keybindings'; +import { Terminal } from '../terminal/terminal'; export class Workbench { @@ -34,6 +35,7 @@ export class Workbench { readonly problems: Problems; readonly settingsEditor: SettingsEditor; readonly keybindingsEditor: KeybindingsEditor; + readonly terminal: Terminal; constructor(private spectron: SpectronApplication) { this.explorer = new Explorer(spectron); @@ -49,6 +51,7 @@ export class Workbench { this.problems = new Problems(spectron); this.settingsEditor = new SettingsEditor(spectron); this.keybindingsEditor = new KeybindingsEditor(spectron); + this.terminal = new Terminal(spectron); } public async saveOpenedFile(): Promise { diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index 6bc1f7f9f8e..a9bd91466ae 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -176,4 +176,6 @@ import './areas/workbench/data-loss.test'; import './areas/git/git.test'; import './areas/statusbar/statusbar.test'; import './areas/debug/debug.test'; +import './areas/workbench/localization.test'; +import './areas/terminal/terminal.test'; // import './areas/workbench/data-migration.test'; \ No newline at end of file diff --git a/test/smoke/src/tests/integrated-terminal.ts b/test/smoke/src/tests/integrated-terminal.ts deleted file mode 100644 index c9bd388fb01..00000000000 --- a/test/smoke/src/tests/integrated-terminal.ts +++ /dev/null @@ -1,40 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; - -import { SpectronApplication, LATEST_PATH, WORKSPACE_PATH } from '../spectron/application'; -import { CommonActions } from '../areas/common'; -import { IntegratedTerminal } from '../areas/integrated-terminal'; - -let app: SpectronApplication; -let common: CommonActions; - -export function testIntegratedTerminal() { - describe('Integrated Terminal', () => { - let terminal: IntegratedTerminal; - - beforeEach(async function () { - app = new SpectronApplication(LATEST_PATH, this.currentTest.fullTitle(), (this.currentTest as any).currentRetry(), [WORKSPACE_PATH]); - common = new CommonActions(app); - terminal = new IntegratedTerminal(app); - - return await app.start(); - }); - afterEach(async function () { - return await app.stop(); - }); - - it(`opens terminal, runs 'echo' and verifies the output`, async function () { - const command = 'echo test'; - await terminal.openTerminal(common); - await app.wait(); - await common.type(command); - await common.enter(); - await app.wait(); - assert.ok(await terminal.commandOutputHas('test'), 'Terminal output does not contain echo.'); - }); - }); -} \ No newline at end of file