提交 78d76cb1 编写于 作者: S Sandeep Somavarapu

smoke test: adopt terminal tests

上级 8ce75db7
......@@ -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 () {
......
/*---------------------------------------------------------------------------------------------
* 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<any> {
// 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<boolean> {
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
......@@ -19,7 +19,6 @@ export enum StatusBarElement {
export class StatusBar {
// private selectorsMap: Map<StatusBarElement, string>;
private readonly mainSelector = 'div[id="workbench.parts.statusbar"]';
constructor(private spectron: SpectronApplication) {
......
......@@ -4,37 +4,21 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { SpectronApplication, LATEST_PATH, WORKSPACE_PATH } from '../../spectron/application';
import { SpectronApplication, LATEST_PATH, WORKSPACE_PATH } from '../spectron/application';
import { CommonActions } from '../areas/common';
import { IntegratedTerminal } from '../areas/integrated-terminal';
describe('Terminal', () => {
let app: SpectronApplication = new SpectronApplication(LATEST_PATH, '', 0, [WORKSPACE_PATH]);
before(() => app.start());
after(() => app.stop());
let app: SpectronApplication;
let common: CommonActions;
it(`opens terminal, runs 'echo' and verifies the output`, async function () {
const expected = new Date().getTime().toString();
await app.workbench.terminal.showTerminal();
export function testIntegratedTerminal() {
describe('Integrated Terminal', () => {
let terminal: IntegratedTerminal;
const currentLine = await app.workbench.terminal.getCurrentLineNumber();
await app.workbench.terminal.runCommand(`echo ${expected}`);
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.');
});
const actual = await app.workbench.terminal.waitForText(currentLine + 1, text => !!text.trim());
assert.equal(actual.trim(), expected);
});
}
\ No newline at end of file
});
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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<void> {
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<boolean> {
const element = await this.spectron.client.element(Terminal.TERMINAL_SELECTOR);
return !!element;
}
public async runCommand(commandText: string): Promise<void> {
await this.spectron.type(commandText);
await this.spectron.client.keys(['Enter', 'NULL']);
}
public async waitForText(line: number, fn: (text: string) => boolean): Promise<string> {
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<number> {
return this.getTerminalText().then(text => text.length);
}
private async getTerminalText(): Promise<string[]> {
const linesText: string[] = await this.spectron.webclient.selectorExecute<string[]>(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
......@@ -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<any> {
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册