diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/application.ts similarity index 96% rename from test/smoke/src/spectron/application.ts rename to test/smoke/src/application.ts index 75bad411cf5..e503b66cbae 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/application.ts @@ -6,13 +6,14 @@ import { Application, SpectronClient as WebClient } from 'spectron'; import { test as testPort } from 'portastic'; import { API } from './client'; -import { ScreenCapturer } from '../helpers/screenshot'; -import { Workbench } from '../areas/workbench/workbench'; +import { ScreenCapturer } from './helpers/screenshot'; +import { Workbench } from './areas/workbench/workbench'; import * as fs from 'fs'; import * as cp from 'child_process'; import * as path from 'path'; import * as mkdirp from 'mkdirp'; -import { sanitize } from '../helpers/utilities'; +import { sanitize } from './helpers/utilities'; +import { SpectronDriver } from './driver'; // Just hope random helps us here, cross your fingers! export async function findFreePort(): Promise { @@ -271,7 +272,9 @@ export class SpectronApplication { } this._screenCapturer = new ScreenCapturer(this.spectron, this._suiteName, screenshotsDirPath); - this._api = new API(this.spectron.client, this.screenCapturer, this.options.waitTime, this.options.verbose); + + const driver = new SpectronDriver(this.spectron.client, this.options.verbose); + this._api = new API(driver, this.screenCapturer, this.options.waitTime); this._workbench = new Workbench(this._api, this.keybindings, this.userDataPath); } diff --git a/test/smoke/src/areas/activitybar/activityBar.ts b/test/smoke/src/areas/activitybar/activityBar.ts index f5942503146..5334408fb52 100644 --- a/test/smoke/src/areas/activitybar/activityBar.ts +++ b/test/smoke/src/areas/activitybar/activityBar.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; export enum ActivityBarPosition { LEFT = 0, diff --git a/test/smoke/src/areas/css/css.test.ts b/test/smoke/src/areas/css/css.test.ts index c0b2c768b9b..2cb9b18e4cf 100644 --- a/test/smoke/src/areas/css/css.test.ts +++ b/test/smoke/src/areas/css/css.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; import { ProblemSeverity, Problems } from '../problems/problems'; export function setup() { diff --git a/test/smoke/src/areas/debug/debug.test.ts b/test/smoke/src/areas/debug/debug.test.ts index 7e924b95b62..e29ed42267f 100644 --- a/test/smoke/src/areas/debug/debug.test.ts +++ b/test/smoke/src/areas/debug/debug.test.ts @@ -8,7 +8,7 @@ import * as http from 'http'; import * as path from 'path'; import * as fs from 'fs'; import * as stripJsonComments from 'strip-json-comments'; -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Debug', () => { diff --git a/test/smoke/src/areas/debug/debug.ts b/test/smoke/src/areas/debug/debug.ts index 78c1c2136a0..3cda1dcb4e7 100644 --- a/test/smoke/src/areas/debug/debug.ts +++ b/test/smoke/src/areas/debug/debug.ts @@ -5,7 +5,7 @@ import { Viewlet } from '../workbench/viewlet'; import { Commands } from '../workbench/workbench'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Editors } from '../editor/editors'; import { Editor } from '../editor/editor'; diff --git a/test/smoke/src/areas/editor/editor.test.ts b/test/smoke/src/areas/editor/editor.test.ts index d3be47f5747..257905b1289 100644 --- a/test/smoke/src/areas/editor/editor.test.ts +++ b/test/smoke/src/areas/editor/editor.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Editor', () => { diff --git a/test/smoke/src/areas/editor/editor.ts b/test/smoke/src/areas/editor/editor.ts index 34c70c65f04..d2f8dee110a 100644 --- a/test/smoke/src/areas/editor/editor.ts +++ b/test/smoke/src/areas/editor/editor.ts @@ -5,7 +5,7 @@ import { References } from './peek'; import { Commands } from '../workbench/workbench'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; const RENAME_BOX = '.monaco-editor .monaco-editor.rename-box'; const RENAME_INPUT = `${RENAME_BOX} .rename-input`; diff --git a/test/smoke/src/areas/editor/editors.ts b/test/smoke/src/areas/editor/editors.ts index 6c708367e3b..870b7ef86c3 100644 --- a/test/smoke/src/areas/editor/editors.ts +++ b/test/smoke/src/areas/editor/editors.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; export class Editors { diff --git a/test/smoke/src/areas/editor/peek.ts b/test/smoke/src/areas/editor/peek.ts index e95b7ccd2b5..e2e34f5a220 100644 --- a/test/smoke/src/areas/editor/peek.ts +++ b/test/smoke/src/areas/editor/peek.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; export class References { diff --git a/test/smoke/src/areas/explorer/explorer.test.ts b/test/smoke/src/areas/explorer/explorer.test.ts index ab77642f6dd..28bf22ca847 100644 --- a/test/smoke/src/areas/explorer/explorer.test.ts +++ b/test/smoke/src/areas/explorer/explorer.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Explorer', () => { diff --git a/test/smoke/src/areas/explorer/explorer.ts b/test/smoke/src/areas/explorer/explorer.ts index d8da8ee2411..f30d9c9ce30 100644 --- a/test/smoke/src/areas/explorer/explorer.ts +++ b/test/smoke/src/areas/explorer/explorer.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Viewlet } from '../workbench/viewlet'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Editors } from '../editor/editors'; import { Commands } from '../workbench/workbench'; diff --git a/test/smoke/src/areas/extensions/extensions.test.ts b/test/smoke/src/areas/extensions/extensions.test.ts index 74aafec003a..703581dc99e 100644 --- a/test/smoke/src/areas/extensions/extensions.test.ts +++ b/test/smoke/src/areas/extensions/extensions.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { SpectronApplication, Quality } from '../../spectron/application'; +import { SpectronApplication, Quality } from '../../application'; export function setup() { describe('Extensions', () => { diff --git a/test/smoke/src/areas/extensions/extensions.ts b/test/smoke/src/areas/extensions/extensions.ts index 0a90538be34..e404bb95251 100644 --- a/test/smoke/src/areas/extensions/extensions.ts +++ b/test/smoke/src/areas/extensions/extensions.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Viewlet } from '../workbench/viewlet'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; const SEARCH_BOX = 'div.extensions-viewlet[id="workbench.view.extensions"] input.search-box'; diff --git a/test/smoke/src/areas/git/git.test.ts b/test/smoke/src/areas/git/git.test.ts index 15eac7b3aa2..5fce52650f2 100644 --- a/test/smoke/src/areas/git/git.test.ts +++ b/test/smoke/src/areas/git/git.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as cp from 'child_process'; -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; const DIFF_EDITOR_LINE_INSERT = '.monaco-diff-editor .editor.modified .line-insert'; const SYNC_STATUSBAR = 'div[id="workbench.parts.statusbar"] .statusbar-entry a[title$="Synchronize Changes"]'; diff --git a/test/smoke/src/areas/git/scm.ts b/test/smoke/src/areas/git/scm.ts index b988b1b2249..f28187bddf4 100644 --- a/test/smoke/src/areas/git/scm.ts +++ b/test/smoke/src/areas/git/scm.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Viewlet } from '../workbench/viewlet'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; const VIEWLET = 'div[id="workbench.view.scm"]'; diff --git a/test/smoke/src/areas/multiroot/multiroot.test.ts b/test/smoke/src/areas/multiroot/multiroot.test.ts index b81df706cf3..22cfdbb0f8a 100644 --- a/test/smoke/src/areas/multiroot/multiroot.test.ts +++ b/test/smoke/src/areas/multiroot/multiroot.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Multiroot', () => { diff --git a/test/smoke/src/areas/preferences/keybindings.ts b/test/smoke/src/areas/preferences/keybindings.ts index bec4324e71e..b6ca0f08fd0 100644 --- a/test/smoke/src/areas/preferences/keybindings.ts +++ b/test/smoke/src/areas/preferences/keybindings.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; const SEARCH_INPUT = '.settings-search-input input'; diff --git a/test/smoke/src/areas/preferences/preferences.test.ts b/test/smoke/src/areas/preferences/preferences.test.ts index c9d8a989cd9..9f0c0bb3c09 100644 --- a/test/smoke/src/areas/preferences/preferences.test.ts +++ b/test/smoke/src/areas/preferences/preferences.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; import { ActivityBarPosition } from '../activitybar/activityBar'; export function setup() { diff --git a/test/smoke/src/areas/preferences/settings.ts b/test/smoke/src/areas/preferences/settings.ts index b1b35ab991d..49262d5228e 100644 --- a/test/smoke/src/areas/preferences/settings.ts +++ b/test/smoke/src/areas/preferences/settings.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; import { Editor } from '../editor/editor'; import { Editors } from '../editor/editors'; diff --git a/test/smoke/src/areas/problems/problems.ts b/test/smoke/src/areas/problems/problems.ts index 00e2230eed8..39086fd390a 100644 --- a/test/smoke/src/areas/problems/problems.ts +++ b/test/smoke/src/areas/problems/problems.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; export enum ProblemSeverity { diff --git a/test/smoke/src/areas/quickopen/quickopen.ts b/test/smoke/src/areas/quickopen/quickopen.ts index 00c1096c63d..289e60e3ba4 100644 --- a/test/smoke/src/areas/quickopen/quickopen.ts +++ b/test/smoke/src/areas/quickopen/quickopen.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Editors } from '../editor/editors'; import { Commands } from '../workbench/workbench'; diff --git a/test/smoke/src/areas/search/search.test.ts b/test/smoke/src/areas/search/search.test.ts index 4b0a5e837d9..caa3444efe4 100644 --- a/test/smoke/src/areas/search/search.test.ts +++ b/test/smoke/src/areas/search/search.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Search', () => { diff --git a/test/smoke/src/areas/search/search.ts b/test/smoke/src/areas/search/search.ts index f0c4a47f507..a6002d7fa35 100644 --- a/test/smoke/src/areas/search/search.ts +++ b/test/smoke/src/areas/search/search.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Viewlet } from '../workbench/viewlet'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; const VIEWLET = 'div[id="workbench.view.search"] .search-view'; diff --git a/test/smoke/src/areas/statusbar/statusbar.test.ts b/test/smoke/src/areas/statusbar/statusbar.test.ts index 28e4aac969e..64b04e95280 100644 --- a/test/smoke/src/areas/statusbar/statusbar.test.ts +++ b/test/smoke/src/areas/statusbar/statusbar.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication, Quality } from '../../spectron/application'; +import { SpectronApplication, Quality } from '../../application'; import { StatusBarElement } from './statusbar'; export function setup() { diff --git a/test/smoke/src/areas/statusbar/statusbar.ts b/test/smoke/src/areas/statusbar/statusbar.ts index 897deae869a..b1217296d97 100644 --- a/test/smoke/src/areas/statusbar/statusbar.ts +++ b/test/smoke/src/areas/statusbar/statusbar.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; export enum StatusBarElement { BRANCH_STATUS = 0, diff --git a/test/smoke/src/areas/terminal/terminal.test.ts b/test/smoke/src/areas/terminal/terminal.test.ts index abbb77e61d5..5713e281cc7 100644 --- a/test/smoke/src/areas/terminal/terminal.test.ts +++ b/test/smoke/src/areas/terminal/terminal.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -// import { SpectronApplication } from '../../spectron/application'; +// import { SpectronApplication } from '../../application'; describe('Terminal', () => { // let app: SpectronApplication; diff --git a/test/smoke/src/areas/terminal/terminal.ts b/test/smoke/src/areas/terminal/terminal.ts index 2149bedc208..511d1d114d9 100644 --- a/test/smoke/src/areas/terminal/terminal.ts +++ b/test/smoke/src/areas/terminal/terminal.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Commands } from '../workbench/workbench'; const PANEL_SELECTOR = 'div[id="workbench.panel.terminal"]'; diff --git a/test/smoke/src/areas/workbench/data-loss.test.ts b/test/smoke/src/areas/workbench/data-loss.test.ts index b06dd647ad8..9d5298bbed8 100644 --- a/test/smoke/src/areas/workbench/data-loss.test.ts +++ b/test/smoke/src/areas/workbench/data-loss.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronApplication } from '../../spectron/application'; +import { SpectronApplication } from '../../application'; export function setup() { describe('Dataloss', () => { diff --git a/test/smoke/src/areas/workbench/data-migration.test.ts b/test/smoke/src/areas/workbench/data-migration.test.ts index 1d30c1bb7a4..582331b6aa9 100644 --- a/test/smoke/src/areas/workbench/data-migration.test.ts +++ b/test/smoke/src/areas/workbench/data-migration.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; -import { SpectronApplication, Quality } from '../../spectron/application'; +import { SpectronApplication, Quality } from '../../application'; import * as rimraf from 'rimraf'; export interface ICreateAppFn { diff --git a/test/smoke/src/areas/workbench/localization.test.ts b/test/smoke/src/areas/workbench/localization.test.ts index 0251a9bf964..ed1f88b0cf1 100644 --- a/test/smoke/src/areas/workbench/localization.test.ts +++ b/test/smoke/src/areas/workbench/localization.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; -import { SpectronApplication, Quality } from '../../spectron/application'; +import { SpectronApplication, Quality } from '../../application'; export function setup() { describe('Localization', () => { diff --git a/test/smoke/src/areas/workbench/viewlet.ts b/test/smoke/src/areas/workbench/viewlet.ts index 92139c3eafc..3c369b9c6ce 100644 --- a/test/smoke/src/areas/workbench/viewlet.ts +++ b/test/smoke/src/areas/workbench/viewlet.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { API } from '../../spectron/client'; +import { API } from '../../client'; export abstract class Viewlet { diff --git a/test/smoke/src/areas/workbench/workbench.ts b/test/smoke/src/areas/workbench/workbench.ts index c8779240bc6..987d6763ddd 100644 --- a/test/smoke/src/areas/workbench/workbench.ts +++ b/test/smoke/src/areas/workbench/workbench.ts @@ -16,7 +16,7 @@ import { Problems } from '../problems/problems'; import { SettingsEditor } from '../preferences/settings'; import { KeybindingsEditor } from '../preferences/keybindings'; import { Terminal } from '../terminal/terminal'; -import { API } from '../../spectron/client'; +import { API } from '../../client'; import { Editors } from '../editor/editors'; export interface Commands { diff --git a/test/smoke/src/spectron/client.ts b/test/smoke/src/client.ts similarity index 51% rename from test/smoke/src/spectron/client.ts rename to test/smoke/src/client.ts index 3f30785a084..a6d14b5350c 100644 --- a/test/smoke/src/spectron/client.ts +++ b/test/smoke/src/client.ts @@ -3,131 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { SpectronClient } from 'spectron'; -import { ScreenCapturer } from '../helpers/screenshot'; - -export interface APIElement { - tagName: string; - className: string; - textContent: string; -} - -export interface Driver { - keys(keys: string[]): Promise; - click(selector: string, xoffset?: number, yoffset?: number): Promise; - doubleClick(selector: string): Promise; - move(selector: string): Promise; - setValue(selector: string, text: string): Promise; - getTitle(): Promise; - - isActiveElement(selector: string): Promise; - getElements(selector: string): Promise; - selectorExecute

(selector: string, script: (elements: HTMLElement[], ...args: any[]) => P, ...args: any[]): Promise

; -} - -export class SpectronDriver implements Driver { - - constructor( - private spectronClient: SpectronClient, - private verbose: boolean - ) { } - - keys(keys: string[]): Promise { - if (this.verbose) { - console.log('- keys:', keys); - } - - this.spectronClient.keys(keys); - return Promise.resolve(); - } - - async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined): Promise { - if (this.verbose) { - console.log('- click:', selector, xoffset, yoffset); - } - - await this.spectronClient.leftClick(selector, xoffset, yoffset); - - if (this.verbose) { - console.log('- click DONE'); - } - } - - async doubleClick(selector: string): Promise { - if (this.verbose) { - console.log('- doubleClick:', selector); - } - - await this.spectronClient.doubleClick(selector); - } - - async move(selector: string): Promise { - if (this.verbose) { - console.log('- move:', selector); - } - - await this.spectronClient.moveToObject(selector); - } - - async setValue(selector: string, text: string): Promise { - if (this.verbose) { - console.log('- setValue:', selector, text); - } - - await this.spectronClient.setValue(selector, text); - } - - async getTitle(): Promise { - if (this.verbose) { - console.log('- getTitle'); - } - - return await this.spectronClient.getTitle(); - } - - async isActiveElement(selector: string): Promise { - if (this.verbose) { - console.log('- isActiveElement:', selector); - } - - const result = await (this.spectronClient.execute(s => document.activeElement.matches(s), selector) as any as Promise<{ value: boolean; }>); - return result.value; - } - - async getElements(selector: string): Promise { - if (this.verbose) { - console.log('- getElements:', selector); - } - - const result = await (this.spectronClient.execute(selector => { - const query = document.querySelectorAll(selector); - const result: APIElement[] = []; - - for (let i = 0; i < query.length; i++) { - const element: HTMLElement = query.item(i); - - result.push({ - tagName: element.tagName, - className: element.className, - textContent: element.textContent || '' - }); - } - - return result; - }, selector) as any as Promise<{ value: APIElement[]; }>); - - return result.value; - } - - async selectorExecute

(selector: string, script: (elements: HTMLElement[], ...args: any[]) => P, ...args: any[]): Promise

{ - if (this.verbose) { - console.log('- selectorExecute:', selector); - } - - let _script = (element, script, ...args) => script(Array.isArray(element) ? element : [element], ...args); - return this.spectronClient.selectorExecute(selector, _script, script, ...args); - } -} +import { ScreenCapturer } from './helpers/screenshot'; +import { Driver, Element } from './driver'; export class API { @@ -135,15 +12,12 @@ export class API { // the time it takes for the actual retry call to complete private retryCount: number; private readonly retryDuration = 100; // in milliseconds - private driver: Driver; constructor( - spectronClient: SpectronClient, + private driver: Driver, private screenCapturer: ScreenCapturer, - waitTime: number, - verbose: boolean + waitTime: number ) { - this.driver = new SpectronDriver(spectronClient, verbose); this.retryCount = (waitTime * 1000) / this.retryDuration; } @@ -186,11 +60,11 @@ export class API { return elements.length; } - waitForElements(selector: string, accept: (result: APIElement[]) => boolean = result => result.length > 0): Promise { + waitForElements(selector: string, accept: (result: Element[]) => boolean = result => result.length > 0): Promise { return this.waitFor(() => this.driver.getElements(selector), accept, `elements with selector ${selector}`) as Promise; } - waitForElement(selector: string, accept: (result: APIElement | undefined) => boolean = result => !!result): Promise { + waitForElement(selector: string, accept: (result: Element | undefined) => boolean = result => !!result): Promise { return this.waitFor(() => this.driver.getElements(selector).then(els => els[0]), accept, `element with selector ${selector}`) as Promise; } diff --git a/test/smoke/src/driver.ts b/test/smoke/src/driver.ts new file mode 100644 index 00000000000..3cd753c1ac5 --- /dev/null +++ b/test/smoke/src/driver.ts @@ -0,0 +1,129 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { SpectronClient } from 'spectron'; + +export interface Element { + tagName: string; + className: string; + textContent: string; +} + +export interface Driver { + keys(keys: string[]): Promise; + click(selector: string, xoffset?: number, yoffset?: number): Promise; + doubleClick(selector: string): Promise; + move(selector: string): Promise; + setValue(selector: string, text: string): Promise; + getTitle(): Promise; + + isActiveElement(selector: string): Promise; + getElements(selector: string): Promise; + selectorExecute

(selector: string, script: (elements: HTMLElement[], ...args: any[]) => P, ...args: any[]): Promise

; +} + +export class SpectronDriver implements Driver { + + constructor( + private spectronClient: SpectronClient, + private verbose: boolean + ) { } + + keys(keys: string[]): Promise { + if (this.verbose) { + console.log('- keys:', keys); + } + + this.spectronClient.keys(keys); + return Promise.resolve(); + } + + async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined): Promise { + if (this.verbose) { + console.log('- click:', selector, xoffset, yoffset); + } + + await this.spectronClient.leftClick(selector, xoffset, yoffset); + + if (this.verbose) { + console.log('- click DONE'); + } + } + + async doubleClick(selector: string): Promise { + if (this.verbose) { + console.log('- doubleClick:', selector); + } + + await this.spectronClient.doubleClick(selector); + } + + async move(selector: string): Promise { + if (this.verbose) { + console.log('- move:', selector); + } + + await this.spectronClient.moveToObject(selector); + } + + async setValue(selector: string, text: string): Promise { + if (this.verbose) { + console.log('- setValue:', selector, text); + } + + await this.spectronClient.setValue(selector, text); + } + + async getTitle(): Promise { + if (this.verbose) { + console.log('- getTitle'); + } + + return await this.spectronClient.getTitle(); + } + + async isActiveElement(selector: string): Promise { + if (this.verbose) { + console.log('- isActiveElement:', selector); + } + + const result = await (this.spectronClient.execute(s => document.activeElement.matches(s), selector) as any as Promise<{ value: boolean; }>); + return result.value; + } + + async getElements(selector: string): Promise { + if (this.verbose) { + console.log('- getElements:', selector); + } + + const result = await (this.spectronClient.execute(selector => { + const query = document.querySelectorAll(selector); + const result: Element[] = []; + + for (let i = 0; i < query.length; i++) { + const element: HTMLElement = query.item(i); + + result.push({ + tagName: element.tagName, + className: element.className, + textContent: element.textContent || '' + }); + } + + return result; + }, selector) as any as Promise<{ value: Element[]; }>); + + return result.value; + } + + async selectorExecute

(selector: string, script: (elements: HTMLElement[], ...args: any[]) => P, ...args: any[]): Promise

{ + if (this.verbose) { + console.log('- selectorExecute:', selector); + } + + let _script = (element, script, ...args) => script(Array.isArray(element) ? element : [element], ...args); + return this.spectronClient.selectorExecute(selector, _script, script, ...args); + } +} diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index eccf18849fa..8d860488309 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -11,7 +11,7 @@ import * as minimist from 'minimist'; import * as tmp from 'tmp'; import * as rimraf from 'rimraf'; import * as mkdirp from 'mkdirp'; -import { SpectronApplication, Quality } from './spectron/application'; +import { SpectronApplication, Quality } from './application'; import { setup as setupDataMigrationTests } from './areas/workbench/data-migration.test'; import { setup as setupDataLossTests } from './areas/workbench/data-loss.test';