diff --git a/src/vs/platform/driver/common/driver.ts b/src/vs/platform/driver/common/driver.ts index b3f472863c6..bcecdfbb74e 100644 --- a/src/vs/platform/driver/common/driver.ts +++ b/src/vs/platform/driver/common/driver.ts @@ -34,12 +34,12 @@ export interface IDriver { doubleClick(windowId: number, selector: string): TPromise; move(windowId: number, selector: string): TPromise; setValue(windowId: number, selector: string, text: string): TPromise; - paste(windowId: number, selector: string, text: string): TPromise; getTitle(windowId: number): TPromise; isActiveElement(windowId: number, selector: string): TPromise; getElements(windowId: number, selector: string, recursive?: boolean): TPromise; typeInEditor(windowId: number, selector: string, text: string): TPromise; getTerminalBuffer(windowId: number, selector: string): TPromise; + writeInTerminal(windowId: number, selector: string, text: string): TPromise; } //*END @@ -52,12 +52,12 @@ export interface IDriverChannel extends IChannel { call(command: 'doubleClick', arg: [number, string]): TPromise; call(command: 'move', arg: [number, string]): TPromise; call(command: 'setValue', arg: [number, string, string]): TPromise; - call(command: 'paste', arg: [number, string, string]): TPromise; call(command: 'getTitle', arg: [number]): TPromise; call(command: 'isActiveElement', arg: [number, string]): TPromise; call(command: 'getElements', arg: [number, string, boolean]): TPromise; call(command: 'typeInEditor', arg: [number, string, string]): TPromise; call(command: 'getTerminalBuffer', arg: [number, string]): TPromise; + call(command: 'writeInTerminal', arg: [number, string, string]): TPromise; call(command: string, arg: any): TPromise; } @@ -75,12 +75,12 @@ export class DriverChannel implements IDriverChannel { case 'doubleClick': return this.driver.doubleClick(arg[0], arg[1]); case 'move': return this.driver.move(arg[0], arg[1]); case 'setValue': return this.driver.setValue(arg[0], arg[1], arg[2]); - case 'paste': return this.driver.paste(arg[0], arg[1], arg[2]); case 'getTitle': return this.driver.getTitle(arg[0]); case 'isActiveElement': return this.driver.isActiveElement(arg[0], arg[1]); case 'getElements': return this.driver.getElements(arg[0], arg[1], arg[2]); 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]); } return undefined; @@ -125,10 +125,6 @@ export class DriverChannelClient implements IDriver { return this.channel.call('setValue', [windowId, selector, text]); } - paste(windowId: number, selector: string, text: string): TPromise { - return this.channel.call('paste', [windowId, selector, text]); - } - getTitle(windowId: number): TPromise { return this.channel.call('getTitle', [windowId]); } @@ -148,6 +144,10 @@ export class DriverChannelClient implements IDriver { getTerminalBuffer(windowId: number, selector: string): TPromise { return this.channel.call('getTerminalBuffer', [windowId, selector]); } + + writeInTerminal(windowId: number, selector: string, text: string): TPromise { + return this.channel.call('writeInTerminal', [windowId, selector, text]); + } } export interface IDriverOptions { @@ -199,12 +199,12 @@ export interface IWindowDriver { doubleClick(selector: string): TPromise; move(selector: string): TPromise; setValue(selector: string, text: string): TPromise; - paste(selector: string, text: string): TPromise; getTitle(): TPromise; isActiveElement(selector: string): TPromise; getElements(selector: string, recursive: boolean): TPromise; typeInEditor(selector: string, text: string): TPromise; getTerminalBuffer(selector: string): TPromise; + writeInTerminal(selector: string, text: string): TPromise; } export interface IWindowDriverChannel extends IChannel { @@ -212,12 +212,12 @@ export interface IWindowDriverChannel extends IChannel { call(command: 'doubleClick', arg: string): TPromise; call(command: 'move', arg: string): TPromise; call(command: 'setValue', arg: [string, string]): TPromise; - call(command: 'paste', arg: [string, string]): TPromise; call(command: 'getTitle'): TPromise; call(command: 'isActiveElement', arg: string): TPromise; call(command: 'getElements', arg: [string, boolean]): TPromise; call(command: 'typeInEditor', arg: [string, string]): TPromise; call(command: 'getTerminalBuffer', arg: string): TPromise; + call(command: 'writeInTerminal', arg: [string, string]): TPromise; call(command: string, arg: any): TPromise; } @@ -231,12 +231,12 @@ export class WindowDriverChannel implements IWindowDriverChannel { case 'doubleClick': return this.driver.doubleClick(arg); case 'move': return this.driver.move(arg); case 'setValue': return this.driver.setValue(arg[0], arg[1]); - case 'paste': return this.driver.paste(arg[0], arg[1]); case 'getTitle': return this.driver.getTitle(); case 'isActiveElement': return this.driver.isActiveElement(arg); case 'getElements': return this.driver.getElements(arg[0], arg[1]); 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]); } return undefined; @@ -265,10 +265,6 @@ export class WindowDriverChannelClient implements IWindowDriver { return this.channel.call('setValue', [selector, text]); } - paste(selector: string, text: string): TPromise { - return this.channel.call('paste', [selector, text]); - } - getTitle(): TPromise { return this.channel.call('getTitle'); } @@ -288,4 +284,8 @@ export class WindowDriverChannelClient implements IWindowDriver { getTerminalBuffer(selector: string): TPromise { return this.channel.call('getTerminalBuffer', selector); } + + writeInTerminal(selector: string, text: string): TPromise { + return this.channel.call('writeInTerminal', [selector, text]); + } } \ No newline at end of file diff --git a/src/vs/platform/driver/electron-browser/driver.ts b/src/vs/platform/driver/electron-browser/driver.ts index 897401df06e..2508ccbb347 100644 --- a/src/vs/platform/driver/electron-browser/driver.ts +++ b/src/vs/platform/driver/electron-browser/driver.ts @@ -109,21 +109,6 @@ class WindowDriver implements IWindowDriver { inputElement.dispatchEvent(event); } - async paste(selector: string, text: string): TPromise { - const element = document.querySelector(selector); - - if (!element) { - throw new Error('Element not found'); - } - - const inputElement = element as HTMLInputElement; - const clipboardData = new DataTransfer(); - clipboardData.setData('text/plain', text); - const event = new ClipboardEvent('paste', { clipboardData } as any); - - inputElement.dispatchEvent(event); - } - async getTitle(): TPromise { return document.title; } @@ -187,6 +172,22 @@ class WindowDriver implements IWindowDriver { return lines; } + async writeInTerminal(selector: string, text: string): TPromise { + const element = document.querySelector(selector); + + if (!element) { + throw new Error('Element not found'); + } + + const xterm = (element as any).xterm; + + if (!xterm) { + throw new Error('Xterm not found'); + } + + xterm.send(text); + } + async openDevTools(): TPromise { await this.windowService.openDevTools({ mode: 'detach' }); } diff --git a/src/vs/platform/driver/electron-main/driver.ts b/src/vs/platform/driver/electron-main/driver.ts index 89cce0f3717..93f68ab7555 100644 --- a/src/vs/platform/driver/electron-main/driver.ts +++ b/src/vs/platform/driver/electron-main/driver.ts @@ -158,11 +158,6 @@ export class Driver implements IDriver, IWindowDriverRegistry { return windowDriver.setValue(selector, text); } - async paste(windowId: number, selector: string, text: string): TPromise { - const windowDriver = await this.getWindowDriver(windowId); - return windowDriver.paste(selector, text); - } - async getTitle(windowId: number): TPromise { const windowDriver = await this.getWindowDriver(windowId); return windowDriver.getTitle(); @@ -188,6 +183,11 @@ export class Driver implements IDriver, IWindowDriverRegistry { return windowDriver.getTerminalBuffer(selector); } + async writeInTerminal(windowId: number, selector: string, text: string): TPromise { + const windowDriver = await this.getWindowDriver(windowId); + return windowDriver.writeInTerminal(selector, text); + } + private async getWindowDriver(windowId: number): TPromise { await this.whenUnfrozen(windowId); diff --git a/test/smoke/src/areas/terminal/terminal.test.ts b/test/smoke/src/areas/terminal/terminal.test.ts index 767e1db734d..d661b13a2dc 100644 --- a/test/smoke/src/areas/terminal/terminal.test.ts +++ b/test/smoke/src/areas/terminal/terminal.test.ts @@ -3,24 +3,24 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// import { Application } from '../../application'; +import { Application } from '../../application'; export function setup() { describe('Terminal', () => { - // it(`opens terminal, runs 'echo' and verifies the output`, async function () { - // const app = this.app as Application; + it(`opens terminal, runs 'echo' and verifies the output`, async function () { + const app = this.app as Application; - // const expected = new Date().getTime().toString(); - // await app.workbench.terminal.showTerminal(); - // await app.workbench.terminal.runCommand(`echo ${expected}`); - // await app.workbench.terminal.waitForTerminalText(terminalText => { - // for (let index = terminalText.length - 2; index >= 0; index--) { - // if (!!terminalText[index] && terminalText[index].trim() === expected) { - // return true; - // } - // } - // return false; - // }); - // }); + const expected = new Date().getTime().toString(); + await app.workbench.terminal.showTerminal(); + await app.workbench.terminal.runCommand(`echo ${expected}`); + await app.workbench.terminal.waitForTerminalText(terminalText => { + for (let index = terminalText.length - 2; index >= 0; index--) { + if (!!terminalText[index] && terminalText[index].trim() === expected) { + return true; + } + } + return false; + }); + }); }); } diff --git a/test/smoke/src/areas/terminal/terminal.ts b/test/smoke/src/areas/terminal/terminal.ts index 6e5e02735ca..f6b1a6bc305 100644 --- a/test/smoke/src/areas/terminal/terminal.ts +++ b/test/smoke/src/areas/terminal/terminal.ts @@ -21,7 +21,7 @@ export class Terminal { } async runCommand(commandText: string): Promise { - await this.code.waitForPaste(XTERM_TEXTAREA, commandText); + await this.code.writeInTerminal(XTERM_SELECTOR, commandText); await this.code.dispatchKeybinding('enter'); } diff --git a/test/smoke/src/vscode/code.ts b/test/smoke/src/vscode/code.ts index 9f5cf3f7e78..17f44b451cf 100644 --- a/test/smoke/src/vscode/code.ts +++ b/test/smoke/src/vscode/code.ts @@ -245,11 +245,6 @@ export class Code { await poll(() => this.driver.setValue(windowId, selector, value), () => true, `set value '${selector}'`); } - async waitForPaste(selector: string, value: string): Promise { - const windowId = await this.getActiveWindowId(); - await poll(() => this.driver.paste(windowId, selector, value), () => true, `paste '${selector}'`); - } - async waitForElements(selector: string, recursive: boolean, accept: (result: IElement[]) => boolean = result => result.length > 0): Promise { const windowId = await this.getActiveWindowId(); return await poll(() => this.driver.getElements(windowId, selector, recursive), accept, `get elements '${selector}'`); @@ -280,6 +275,11 @@ export class Code { await poll(() => this.driver.getTerminalBuffer(windowId, selector), accept, `get terminal buffer '${selector}'`); } + async writeInTerminal(selector: string, value: string): Promise { + const windowId = await this.getActiveWindowId(); + await poll(() => this.driver.writeInTerminal(windowId, selector, value), () => true, `writeInTerminal '${selector}'`); + } + private async getActiveWindowId(): Promise { if (typeof this._activeWindowId !== 'number') { const windows = await this.driver.getWindowIds();