diff --git a/test/smoke/src/areas/css/css.test.ts b/test/smoke/src/areas/css/css.test.ts index 7b064431e0a..d0b4c01b201 100644 --- a/test/smoke/src/areas/css/css.test.ts +++ b/test/smoke/src/areas/css/css.test.ts @@ -21,7 +21,7 @@ describe('CSS', () => { it('verifies warnings for the empty rule', async () => { await app.workbench.quickopen.openFile('style.css'); - await app.client.type('.foo{}'); + await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}'); let warning = await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.WARNING)); await app.screenCapturer.capture('CSS Warning in editor'); @@ -37,7 +37,7 @@ describe('CSS', () => { it('verifies that warning becomes an error once setting changed', async () => { await app.workbench.settingsEditor.addUserSetting('css.lint.emptyRules', '"error"'); await app.workbench.quickopen.openFile('style.css'); - await app.client.type('.foo{}'); + await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}'); let error = await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.ERROR)); await app.screenCapturer.capture('CSS Error in editor'); diff --git a/test/smoke/src/areas/debug/debug.ts b/test/smoke/src/areas/debug/debug.ts index a47299176d2..7537ca1e69a 100644 --- a/test/smoke/src/areas/debug/debug.ts +++ b/test/smoke/src/areas/debug/debug.ts @@ -41,7 +41,7 @@ export class Debug extends Viewlet { } async openDebugViewlet(): Promise { - await this.spectron.command('workbench.view.debug'); + await this.spectron.runCommand('workbench.view.debug'); await this.spectron.client.waitForElement(DEBUG_VIEW); } @@ -114,8 +114,8 @@ export class Debug extends Viewlet { async waitForReplCommand(text: string, accept: (result: string) => boolean): Promise { await this.spectron.workbench.quickopen.runCommand('Debug: Focus Debug Console'); await this.spectron.client.waitForActiveElement(REPL_FOCUSED); + await this.spectron.client.setValue(REPL_FOCUSED, text); - await this.spectron.client.keys(text); // Wait for the keys to be picked up by the editor model such that repl evalutes what just got typed await this.spectron.workbench.editor.waitForEditorContents('debug:input', s => s.indexOf(text) >= 0); await this.spectron.client.keys(['Enter', 'NULL']); diff --git a/test/smoke/src/areas/editor/editor.test.ts b/test/smoke/src/areas/editor/editor.test.ts index 38634bb5a92..3ceb7d6f0a4 100644 --- a/test/smoke/src/areas/editor/editor.test.ts +++ b/test/smoke/src/areas/editor/editor.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 { SpectronApplication } from '../../spectron/application'; describe('Editor', () => { @@ -31,14 +29,9 @@ describe('Editor', () => { it(`renames local 'app' variable`, async function () { await app.workbench.quickopen.openFile('www'); - - const selector = await app.workbench.editor.getSelector('app', 7); - const rename = await app.workbench.editor.rename('app', 7); - await rename.rename('newApp'); - - const actual = await app.client.waitForText(selector, 'newApp'); + await app.workbench.editor.rename('www', 7, 'app', 'newApp'); + await app.workbench.editor.waitForEditorContents('www', contents => contents.indexOf('newApp') > -1); await app.screenCapturer.capture('Rename result'); - assert.equal(actual, 'newApp'); }); it('folds/unfolds the code correctly', async function () { diff --git a/test/smoke/src/areas/editor/editor.ts b/test/smoke/src/areas/editor/editor.ts index 5c81f8f47bd..51c27c84d0a 100644 --- a/test/smoke/src/areas/editor/editor.ts +++ b/test/smoke/src/areas/editor/editor.ts @@ -6,7 +6,9 @@ import { SpectronApplication } from '../../spectron/application'; import { QuickOutline } from './quickoutline'; import { References } from './peek'; -import { Rename } from './rename'; + +const RENAME_BOX = '.monaco-editor .monaco-editor.rename-box'; +const RENAME_INPUT = `${RENAME_BOX} .rename-input`; export class Editor { @@ -18,13 +20,13 @@ export class Editor { constructor(private spectron: SpectronApplication) { } - public async openOutline(): Promise { + async openOutline(): Promise { const outline = new QuickOutline(this.spectron); await outline.open(); return outline; } - public async findReferences(term: string, line: number): Promise { + async findReferences(term: string, line: number): Promise { await this.clickOnTerm(term, line); await this.spectron.workbench.quickopen.runCommand('Find All References'); const references = new References(this.spectron); @@ -32,20 +34,22 @@ export class Editor { return references; } - public async rename(term: string, line: number): Promise { - await this.clickOnTerm(term, line); + async rename(filename: string, line: number, from: string, to: string): Promise { + await this.clickOnTerm(from, line); await this.spectron.workbench.quickopen.runCommand('Rename Symbol'); - const rename = new Rename(term, this.spectron); - await rename.waitUntilOpen(); - return rename; + + await this.spectron.client.waitForActiveElement(RENAME_INPUT); + await this.spectron.client.setValue(RENAME_INPUT, to); + + await this.spectron.client.keys(['Enter', 'NULL']); } - public async gotoDefinition(term: string, line: number): Promise { + async gotoDefinition(term: string, line: number): Promise { await this.clickOnTerm(term, line); await this.spectron.workbench.quickopen.runCommand('Go to Definition'); } - public async peekDefinition(term: string, line: number): Promise { + async peekDefinition(term: string, line: number): Promise { await this.clickOnTerm(term, line); await this.spectron.workbench.quickopen.runCommand('Peek Definition'); const peek = new References(this.spectron); @@ -53,7 +57,7 @@ export class Editor { return peek; } - public async waitForHighlightingLine(line: number): Promise { + async waitForHighlightingLine(line: number): Promise { const currentLineIndex = await this.getViewLineIndex(line); if (currentLineIndex) { await this.spectron.client.waitForElement(`.monaco-editor .view-overlays>:nth-child(${currentLineIndex}) .current-line`); @@ -62,60 +66,72 @@ export class Editor { throw new Error('Cannot find line ' + line); } - public async getSelector(term: string, line: number): Promise { + async getSelector(term: string, line: number): Promise { const lineIndex = await this.getViewLineIndex(line); const classNames = await this.spectron.client.waitFor(() => this.getClassSelectors(term, lineIndex), classNames => classNames && !!classNames.length, 'Getting class names for editor lines'); return `${Editor.VIEW_LINES}>:nth-child(${lineIndex}) span span.${classNames[0]}`; } - public async foldAtLine(line: number): Promise { + async foldAtLine(line: number): Promise { const lineIndex = await this.getViewLineIndex(line); await this.spectron.client.waitAndClick(Editor.FOLDING_EXPANDED.replace('${INDEX}', '' + lineIndex)); await this.spectron.client.waitForElement(Editor.FOLDING_COLLAPSED.replace('${INDEX}', '' + lineIndex)); } - public async unfoldAtLine(line: number): Promise { + async unfoldAtLine(line: number): Promise { const lineIndex = await this.getViewLineIndex(line); await this.spectron.client.waitAndClick(Editor.FOLDING_COLLAPSED.replace('${INDEX}', '' + lineIndex)); await this.spectron.client.waitForElement(Editor.FOLDING_EXPANDED.replace('${INDEX}', '' + lineIndex)); } - public async waitUntilHidden(line: number): Promise { + async waitUntilHidden(line: number): Promise { await this.spectron.client.waitFor(() => this.getViewLineIndexWithoutWait(line), lineNumber => lineNumber === undefined, 'Waiting until line number is hidden'); } - public async waitUntilShown(line: number): Promise { + async waitUntilShown(line: number): Promise { await this.getViewLineIndex(line); } - public async clickOnTerm(term: string, line: number): Promise { + async clickOnTerm(term: string, line: number): Promise { const selector = await this.getSelector(term, line); await this.spectron.client.waitAndClick(selector); } - public async waitForTypeInEditor(filename: string, text: string): Promise { - const editor = `.monaco-editor[data-uri$="${filename}"]`; - await this.spectron.client.waitAndClick(editor); + async waitForTypeInEditor(filename: string, text: string, selectorPrefix = ''): Promise { + const editor = [ + selectorPrefix || '', + `.monaco-editor[data-uri$="${filename}"]` + ].join(' '); + + await this.spectron.client.element(editor); const textarea = `${editor} textarea`; await this.spectron.client.waitForActiveElement(textarea); - await this.spectron.client.type(text); + // https://github.com/Microsoft/vscode/issues/34203#issuecomment-334441786 + for (let i = 0; i < text.length; i++) { + this.spectron.client.spectron.client.keys([text[i], 'NULL']); + await new Promise(c => setTimeout(c, 50)); + } - await this.waitForEditorContents(filename, c => c.indexOf(text) > -1); + await this.waitForEditorContents(filename, c => c.indexOf(text) > -1, selectorPrefix); } - public async waitForEditorContents(filename: string, accept: (contents: string) => boolean): Promise { - const selector = `.monaco-editor[data-uri$="${filename}"] .view-lines`; + async waitForEditorContents(filename: string, accept: (contents: string) => boolean, selectorPrefix = ''): Promise { + const selector = [ + selectorPrefix || '', + `.monaco-editor[data-uri$="${filename}"] .view-lines` + ].join(' '); + return this.spectron.client.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' '))); } - public async waitForActiveEditor(filename: string): Promise { + async waitForActiveEditor(filename: string): Promise { const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`; return this.spectron.client.waitForActiveElement(selector); } - // public async waitForActiveEditorFirstLineText(filename: string): Promise { + // async waitForActiveEditorFirstLineText(filename: string): Promise { // const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`; // const result = await this.spectron.client.waitFor( // () => this.spectron.client.spectron.client.execute(s => { diff --git a/test/smoke/src/areas/editor/quickoutline.ts b/test/smoke/src/areas/editor/quickoutline.ts index 35fab316ee0..852bd8b9145 100644 --- a/test/smoke/src/areas/editor/quickoutline.ts +++ b/test/smoke/src/areas/editor/quickoutline.ts @@ -14,7 +14,7 @@ export class QuickOutline extends QuickOpen { public async open(): Promise { await this.spectron.client.waitFor(async () => { - await this.spectron.command('workbench.action.gotoSymbol'); + await this.spectron.runCommand('workbench.action.gotoSymbol'); const entry = await this.spectron.client.element('div[aria-label="Quick Picker"] .monaco-tree-rows.show-twisties div.monaco-tree-row .quick-open-entry'); if (entry) { const text = await this.spectron.client.getText('div[aria-label="Quick Picker"] .monaco-tree-rows.show-twisties div.monaco-tree-row .quick-open-entry .monaco-icon-label .label-name .monaco-highlighted-label span'); diff --git a/test/smoke/src/areas/editor/rename.ts b/test/smoke/src/areas/editor/rename.ts deleted file mode 100644 index 521798c9ba3..00000000000 --- a/test/smoke/src/areas/editor/rename.ts +++ /dev/null @@ -1,26 +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'; - -export class Rename { - - private static RENAME_BOX = '.monaco-editor .monaco-editor.rename-box'; - private static RENAME_INPUT = `${Rename.RENAME_BOX} .rename-input`; - - constructor(private term: string, private spectron: SpectronApplication) { - } - - public async waitUntilOpen(): Promise { - await this.spectron.client.waitForVisibility(Rename.RENAME_BOX); - await this.spectron.client.waitForValue(Rename.RENAME_INPUT, this.term); - } - - public async rename(newTerm: string): Promise { - await this.spectron.client.type(newTerm); - await this.spectron.client.keys(['Enter', 'NULL']); - await this.spectron.client.waitForVisibility(Rename.RENAME_BOX, result => !result); - } -} \ No newline at end of file diff --git a/test/smoke/src/areas/explorer/explorer.test.ts b/test/smoke/src/areas/explorer/explorer.test.ts index 658be5959b7..581851e0ab8 100644 --- a/test/smoke/src/areas/explorer/explorer.test.ts +++ b/test/smoke/src/areas/explorer/explorer.test.ts @@ -21,8 +21,7 @@ describe('Explorer', () => { 'jsconfig.json' ]; - await app.workbench.quickopen.openQuickOpen(); - await app.client.type('.js'); + await app.workbench.quickopen.openQuickOpen('.js'); await app.workbench.quickopen.waitForQuickOpenElements(names => expectedNames.every(n => names.some(m => n === m))); await app.client.keys(['Escape', 'NULL']); }); @@ -34,8 +33,7 @@ describe('Explorer', () => { 'package.json' ]; - await app.workbench.quickopen.openQuickOpen(); - await app.client.type('a.s'); + await app.workbench.quickopen.openQuickOpen('a.s'); await app.workbench.quickopen.waitForQuickOpenElements(names => expectedNames.every(n => names.some(m => n === m))); await app.client.keys(['Escape', 'NULL']); }); diff --git a/test/smoke/src/areas/explorer/explorer.ts b/test/smoke/src/areas/explorer/explorer.ts index e799bc0f225..1dd454462ac 100644 --- a/test/smoke/src/areas/explorer/explorer.ts +++ b/test/smoke/src/areas/explorer/explorer.ts @@ -17,7 +17,7 @@ export class Explorer extends Viewlet { } public openExplorerView(): Promise { - return this.spectron.command('workbench.view.explorer'); + return this.spectron.runCommand('workbench.view.explorer'); } public getOpenEditorsViewTitle(): Promise { diff --git a/test/smoke/src/areas/extensions/extensions.ts b/test/smoke/src/areas/extensions/extensions.ts index 62e0bb936db..d0c3f97320d 100644 --- a/test/smoke/src/areas/extensions/extensions.ts +++ b/test/smoke/src/areas/extensions/extensions.ts @@ -6,6 +6,8 @@ import { SpectronApplication } from '../../spectron/application'; import { Viewlet } from '../workbench/viewlet'; +const SEARCH_BOX = 'div.extensions-viewlet[id="workbench.view.extensions"] input.search-box'; + export class Extensions extends Viewlet { constructor(spectron: SpectronApplication) { @@ -13,21 +15,18 @@ export class Extensions extends Viewlet { } async openExtensionsViewlet(): Promise { - await this.spectron.command('workbench.view.extensions'); + await this.spectron.runCommand('workbench.view.extensions'); await this.waitForExtensionsViewlet(); } async waitForExtensionsViewlet(): Promise { - await this.spectron.client.waitForActiveElement('div.extensions-viewlet[id="workbench.view.extensions"] input.search-box'); + await this.spectron.client.waitForActiveElement(SEARCH_BOX); } async searchForExtension(name: string): Promise { - const searchBoxSelector = 'div.extensions-viewlet[id="workbench.view.extensions"] .search-box'; - - await this.spectron.client.clearElement(searchBoxSelector); - await this.spectron.client.click(searchBoxSelector); - await this.spectron.client.waitForActiveElement('div.extensions-viewlet[id="workbench.view.extensions"] input.search-box'); - await this.spectron.client.keys(name); + await this.spectron.client.click(SEARCH_BOX); + await this.spectron.client.waitForActiveElement(SEARCH_BOX); + await this.spectron.client.setValue(SEARCH_BOX, name); } async installExtension(name: string): Promise { diff --git a/test/smoke/src/areas/git/git.test.ts b/test/smoke/src/areas/git/git.test.ts index 73d5d99f5e2..57c0240b1d4 100644 --- a/test/smoke/src/areas/git/git.test.ts +++ b/test/smoke/src/areas/git/git.test.ts @@ -19,11 +19,11 @@ describe('Git', () => { await app.workbench.scm.openSCMViewlet(); await app.workbench.quickopen.openFile('app.js'); - await app.client.type('.foo{}'); + await app.workbench.editor.waitForTypeInEditor('app.js', '.foo{}'); await app.workbench.saveOpenedFile(); await app.workbench.quickopen.openFile('index.jade'); - await app.client.type('hello world'); + await app.workbench.editor.waitForTypeInEditor('index.jade', 'hello world'); await app.workbench.saveOpenedFile(); await app.workbench.scm.refreshSCMViewlet(); diff --git a/test/smoke/src/areas/git/scm.ts b/test/smoke/src/areas/git/scm.ts index 90642445171..94576417744 100644 --- a/test/smoke/src/areas/git/scm.ts +++ b/test/smoke/src/areas/git/scm.ts @@ -30,7 +30,7 @@ export class SCM extends Viewlet { } async openSCMViewlet(): Promise { - await this.spectron.command('workbench.view.scm'); + await this.spectron.runCommand('workbench.view.scm'); await this.spectron.client.waitForElement(SCM_INPUT); } @@ -95,8 +95,9 @@ export class SCM extends Viewlet { } async commit(message: string): Promise { - await this.spectron.client.click(SCM_INPUT); - await this.spectron.client.type(message); - await this.spectron.client.click(COMMIT_COMMAND); + await this.spectron.client.waitAndClick(SCM_INPUT); + await this.spectron.client.waitForActiveElement(SCM_INPUT); + await this.spectron.client.setValue(SCM_INPUT, message); + await this.spectron.client.waitAndClick(COMMIT_COMMAND); } } \ No newline at end of file diff --git a/test/smoke/src/areas/multiroot/multiroot.test.ts b/test/smoke/src/areas/multiroot/multiroot.test.ts index 92c50c070e7..f341f3da137 100644 --- a/test/smoke/src/areas/multiroot/multiroot.test.ts +++ b/test/smoke/src/areas/multiroot/multiroot.test.ts @@ -16,8 +16,7 @@ describe('Multiroot', () => { after(() => app.stop()); it('shows results from all folders', async function () { - await app.workbench.quickopen.openQuickOpen(); - await app.workbench.quickopen.type('*.*'); + await app.workbench.quickopen.openQuickOpen('*.*'); await app.workbench.quickopen.waitForQuickOpenElements(names => names.length >= 6); await app.workbench.quickopen.closeQuickOpen(); diff --git a/test/smoke/src/areas/preferences/keybindings.ts b/test/smoke/src/areas/preferences/keybindings.ts index c6c7431ff19..1de2eba3470 100644 --- a/test/smoke/src/areas/preferences/keybindings.ts +++ b/test/smoke/src/areas/preferences/keybindings.ts @@ -5,36 +5,24 @@ import { SpectronApplication } from '../../spectron/application'; +const SEARCH_INPUT = '.settings-search-input input'; + export class KeybindingsEditor { - constructor(private spectron: SpectronApplication) { - // noop - } + constructor(private spectron: SpectronApplication) { } - public async openKeybindings(): Promise { - await this.spectron.command('workbench.action.openGlobalKeybindings'); - await this.spectron.client.waitForElement('.settings-search-input .synthetic-focus'); - } + async updateKeybinding(command: string, keys: string[], ariaLabel: string): Promise { + await this.spectron.runCommand('workbench.action.openGlobalKeybindings'); + await this.spectron.client.waitForActiveElement(SEARCH_INPUT); + await this.spectron.client.setValue(SEARCH_INPUT, command); - public async search(text: string, select: boolean = false): Promise { - await this.spectron.client.type(text); - if (select) { - await this.spectron.client.waitAndClick('div[aria-label="Keybindings"] .monaco-list-row.keybinding-item'); - await this.spectron.client.waitForElement('div[aria-label="Keybindings"] .monaco-list-row.keybinding-item.focused.selected'); - } - } + await this.spectron.client.waitAndClick('div[aria-label="Keybindings"] .monaco-list-row.keybinding-item'); + await this.spectron.client.waitForElement('div[aria-label="Keybindings"] .monaco-list-row.keybinding-item.focused.selected'); - public async openDefineKeybindingDialog(): Promise { await this.spectron.client.waitAndClick('div[aria-label="Keybindings"] .monaco-list-row.keybinding-item .action-item .icon.add'); - return this.spectron.client.waitForElement('.defineKeybindingWidget .monaco-inputbox.synthetic-focus'); - } + await this.spectron.client.waitForElement('.defineKeybindingWidget .monaco-inputbox.synthetic-focus'); - public async updateKeybinding(command: string, keys: string[], ariaLabel: string): Promise { - await this.search(command, true); - await this.openDefineKeybindingDialog(); - await this.spectron.client.keys(keys); - await this.spectron.client.keys(['Enter', 'NULL']); + await this.spectron.client.keys([...keys, 'NULL', 'Enter', 'NULL']); await this.spectron.client.waitForElement(`div[aria-label="Keybindings"] div[aria-label="Keybinding is ${ariaLabel}."]`); } - } \ 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 3074be7fd47..4a9939bf2b3 100644 --- a/test/smoke/src/areas/preferences/preferences.test.ts +++ b/test/smoke/src/areas/preferences/preferences.test.ts @@ -30,8 +30,7 @@ describe('Preferences', () => { it(`changes 'workbench.action.toggleSidebarPosition' command key binding and verifies it`, async function () { assert.ok(await app.workbench.activitybar.getActivityBar(ActivityBarPosition.LEFT), 'Activity bar should be positioned on the left.'); - await app.workbench.keybindingsEditor.openKeybindings(); - await app.workbench.keybindingsEditor.updateKeybinding('workbench.action.toggleSidebarPosition', ['Control', 'u', 'NULL'], 'Control+U'); + await app.workbench.keybindingsEditor.updateKeybinding('workbench.action.toggleSidebarPosition', ['Control', 'u'], 'Control+U'); await app.client.keys(['Control', 'u', 'NULL']); assert.ok(await app.workbench.activitybar.getActivityBar(ActivityBarPosition.RIGHT), 'Activity bar was not moved to right after toggling its position.'); diff --git a/test/smoke/src/areas/preferences/settings.ts b/test/smoke/src/areas/preferences/settings.ts index 24fd9d63e12..ce28c1b2c9e 100644 --- a/test/smoke/src/areas/preferences/settings.ts +++ b/test/smoke/src/areas/preferences/settings.ts @@ -10,30 +10,26 @@ export enum ActivityBarPosition { RIGHT = 1 }; +const SEARCH_INPUT = '.settings-search-input input'; +const EDITOR = '.editable-preferences-editor-container .monaco-editor textarea'; + export class SettingsEditor { - constructor(private spectron: SpectronApplication) { - // noop - } - - async openUserSettings(): Promise { - await this.spectron.command('workbench.action.openGlobalSettings'); - await this.spectron.client.waitForActiveElement('.settings-search-input input'); - } - - async focusEditableSettings(): Promise { - await this.spectron.client.keys(['ArrowDown', 'NULL'], false); - await this.spectron.client.waitForActiveElement('.editable-preferences-editor-container .monaco-editor textarea'); - await this.spectron.client.keys(['ArrowRight', 'NULL'], false); - } + constructor(private spectron: SpectronApplication) { } async addUserSetting(setting: string, value: string): Promise { - await this.openUserSettings(); - await this.focusEditableSettings(); + await this.spectron.runCommand('workbench.action.openGlobalSettings'); + await this.spectron.client.waitForActiveElement(SEARCH_INPUT); + + await this.spectron.client.keys(['ArrowDown', 'NULL']); + await this.spectron.client.waitForActiveElement(EDITOR); + + await this.spectron.client.keys(['ArrowRight', 'NULL']); await this.spectron.screenCapturer.capture('user settings is open and focused'); - await this.spectron.client.keys(`"${setting}": ${value},`); + await this.spectron.workbench.editor.waitForTypeInEditor('settings.json', `"${setting}": ${value}`, '.editable-preferences-editor-container'); await this.spectron.workbench.saveOpenedFile(); + await this.spectron.screenCapturer.capture('user settings has changed'); } } \ No newline at end of file diff --git a/test/smoke/src/areas/problems/problems.ts b/test/smoke/src/areas/problems/problems.ts index 2e6f7bc1e5a..ed1ea406c1a 100644 --- a/test/smoke/src/areas/problems/problems.ts +++ b/test/smoke/src/areas/problems/problems.ts @@ -20,14 +20,14 @@ export class Problems { public async showProblemsView(): Promise { if (!await this.isVisible()) { - await this.spectron.command('workbench.actions.view.problems'); + await this.spectron.runCommand('workbench.actions.view.problems'); await this.waitForProblemsView(); } } public async hideProblemsView(): Promise { if (await this.isVisible()) { - await this.spectron.command('workbench.actions.view.problems'); + await this.spectron.runCommand('workbench.actions.view.problems'); await this.spectron.client.waitForElement(Problems.PROBLEMS_VIEW_SELECTOR, el => !el); } } diff --git a/test/smoke/src/areas/quickopen/quickopen.ts b/test/smoke/src/areas/quickopen/quickopen.ts index 5260874be38..4f70d280c11 100644 --- a/test/smoke/src/areas/quickopen/quickopen.ts +++ b/test/smoke/src/areas/quickopen/quickopen.ts @@ -15,28 +15,22 @@ export class QuickOpen { constructor(readonly spectron: SpectronApplication) { } - async openQuickOpen(): Promise { - await this.spectron.command('workbench.action.quickOpen'); + async openQuickOpen(value: string): Promise { + await this.spectron.runCommand('workbench.action.quickOpen'); await this.waitForQuickOpenOpened(); - } - async openCommandPallette(): Promise { - await this.spectron.command('workbench.action.showCommands'); - await this.waitForQuickOpenOpened(); + if (value) { + await this.spectron.client.setValue(QuickOpen.QUICK_OPEN_INPUT, value); + } } async closeQuickOpen(): Promise { - await this.spectron.command('workbench.action.closeQuickOpen'); + await this.spectron.runCommand('workbench.action.closeQuickOpen'); await this.waitForQuickOpenClosed(); } - async type(text: string): Promise { - await this.spectron.client.type(text); - } - async openFile(fileName: string): Promise { - await this.openQuickOpen(); - await this.type(fileName); + await this.openQuickOpen(fileName); await this.waitForQuickOpenElements(names => names.some(n => n === fileName)); await this.spectron.client.keys(['Enter', 'NULL']); @@ -45,10 +39,7 @@ export class QuickOpen { } async runCommand(commandText: string): Promise { - await this.openCommandPallette(); - - // type the text - await this.type(commandText); + await this.openQuickOpen(`> ${commandText}`); // wait for best choice to be focused await this.spectron.client.waitForTextContent(QuickOpen.QUICK_OPEN_FOCUSED_ELEMENT, commandText); @@ -69,7 +60,7 @@ export class QuickOpen { } async submit(text: string): Promise { - await this.spectron.client.type(text); + await this.spectron.client.setValue(QuickOpen.QUICK_OPEN_INPUT, text); await this.spectron.client.keys(['Enter', 'NULL']); await this.waitForQuickOpenClosed(); } diff --git a/test/smoke/src/areas/search/search.test.ts b/test/smoke/src/areas/search/search.test.ts index 5c0a7f46cd3..60972beb081 100644 --- a/test/smoke/src/areas/search/search.test.ts +++ b/test/smoke/src/areas/search/search.test.ts @@ -18,29 +18,23 @@ describe('Search', () => { }); it('searches only for *.js files & checks for correct result number', async function () { - await app.workbench.search.openSearchViewlet(); await app.workbench.search.searchFor('body'); await app.workbench.search.showQueryDetails(); - await app.workbench.search.setFilesToIncludeTextAndSearch('*.js'); - + await app.workbench.search.setFilesToIncludeText('*.js'); await app.workbench.search.submitSearch(); await app.workbench.search.waitForResultText('4 results in 1 file'); - await app.workbench.search.setFilesToIncludeTextAndSearch(''); + await app.workbench.search.setFilesToIncludeText(''); await app.workbench.search.hideQueryDetails(); }); it('dismisses result & checks for correct result number', async function () { - await app.workbench.search.openSearchViewlet(); await app.workbench.search.searchFor('body'); - await app.workbench.search.removeFileMatch(1); - await app.workbench.search.waitForResultText('3 results in 3 files'); }); it('replaces first search result with a replace term', async function () { - await app.workbench.search.openSearchViewlet(); await app.workbench.search.searchFor('body'); await app.workbench.search.setReplaceText('ydob'); diff --git a/test/smoke/src/areas/search/search.ts b/test/smoke/src/areas/search/search.ts index 3d3642ea37a..4267da79f47 100644 --- a/test/smoke/src/areas/search/search.ts +++ b/test/smoke/src/areas/search/search.ts @@ -6,92 +6,79 @@ import { SpectronApplication } from '../../spectron/application'; import { Viewlet } from '../workbench/viewlet'; -export class Search extends Viewlet { +const VIEWLET = 'div[id="workbench.view.search"] .search-viewlet'; +const INPUT = `${VIEWLET} .search-widget .search-container .monaco-inputbox input`; +const INCLUDE_INPUT = `${VIEWLET} .query-details .monaco-inputbox input[aria-label="Search Include Patterns"]`; - static SEARCH_VIEWLET_XPATH = 'div[id="workbench.view.search"] .search-viewlet'; +export class Search extends Viewlet { constructor(spectron: SpectronApplication) { super(spectron); } - public async openSearchViewlet(): Promise { - if (!await this.isSearchViewletFocused()) { - await this.spectron.command('workbench.view.search'); - await this.spectron.client.waitForElement(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox.synthetic-focus input`); - } + async openSearchViewlet(): Promise { + await this.spectron.runCommand('workbench.view.search'); + await this.spectron.client.waitForActiveElement(INPUT); } - public async isSearchViewletFocused(): Promise { - const element = await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox.synthetic-focus input`); - return !!element; - } - - public async searchFor(text: string): Promise { - const searchBoxSelector = `${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox input`; - - await this.spectron.client.clearElement(searchBoxSelector); - await this.spectron.client.click(searchBoxSelector); - await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox.synthetic-focus input`); - - await this.spectron.client.keys(text); - + async searchFor(text: string): Promise { + await this.spectron.client.click(INPUT); + await this.spectron.client.waitForActiveElement(INPUT); + await this.spectron.client.setValue(INPUT, text); await this.submitSearch(); } - public async submitSearch(): Promise { - await this.spectron.client.click(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox input`); - await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .search-container .monaco-inputbox.synthetic-focus input`); - await this.spectron.client.keys(['NULL', 'Enter', 'NULL'], false); - await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .messages[aria-hidden="false"]`); + async submitSearch(): Promise { + await this.spectron.client.click(INPUT); + await this.spectron.client.waitForActiveElement(INPUT); + + await this.spectron.client.keys(['Enter', 'NULL']); + await this.spectron.client.element(`${VIEWLET} .messages[aria-hidden="false"]`); } - public async setFilesToIncludeTextAndSearch(text: string): Promise { - await this.spectron.client.click(`${Search.SEARCH_VIEWLET_XPATH} .query-details .monaco-inputbox input[aria-label="Search Include Patterns"]`); - await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .query-details .monaco-inputbox.synthetic-focus input[aria-label="Search Include Patterns"]`); - await this.spectron.client.clearElement(`${Search.SEARCH_VIEWLET_XPATH} .query-details .monaco-inputbox.synthetic-focus input[aria-label="Search Include Patterns"]`); - - if (text) { - await this.spectron.client.keys(text); - } + async setFilesToIncludeText(text: string): Promise { + await this.spectron.client.click(INCLUDE_INPUT); + await this.spectron.client.waitForActiveElement(INCLUDE_INPUT); + await this.spectron.client.setValue(INCLUDE_INPUT, text || ''); } - public async showQueryDetails(): Promise { + async showQueryDetails(): Promise { if (!await this.areDetailsVisible()) { - await this.spectron.client.waitAndClick(`${Search.SEARCH_VIEWLET_XPATH} .query-details .more`); + await this.spectron.client.waitAndClick(`${VIEWLET} .query-details .more`); } } - public async hideQueryDetails(): Promise { + async hideQueryDetails(): Promise { if (await this.areDetailsVisible()) { - await this.spectron.client.waitAndClick(`${Search.SEARCH_VIEWLET_XPATH} .query-details.more .more`); + await this.spectron.client.waitAndClick(`${VIEWLET} .query-details.more .more`); } } - public async areDetailsVisible(): Promise { - const element = await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .query-details.more`); + async areDetailsVisible(): Promise { + const element = await this.spectron.client.element(`${VIEWLET} .query-details.more`); return !!element; } - public async removeFileMatch(index: number): Promise { - await this.spectron.client.waitAndmoveToObject(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch`); - const file = await this.spectron.client.waitForText(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`); - await this.spectron.client.click(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-remove`); - await this.spectron.client.waitForText(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`, void 0, result => result !== file); + async removeFileMatch(index: number): Promise { + await this.spectron.client.waitAndMoveToObject(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch`); + const file = await this.spectron.client.waitForText(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`); + await this.spectron.client.waitAndClick(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-remove`); + await this.spectron.client.waitForText(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch a.label-name`, void 0, result => result !== file); } - public async setReplaceText(text: string): Promise { - await this.spectron.client.waitAndClick(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .monaco-button.toggle-replace-button.collapse`); - await this.spectron.client.waitAndClick(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .replace-container .monaco-inputbox input[title="Replace"]`); - await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`); - await this.spectron.client.setValue(`${Search.SEARCH_VIEWLET_XPATH} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`, text); + async setReplaceText(text: string): Promise { + await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .monaco-button.toggle-replace-button.collapse`); + await this.spectron.client.waitAndClick(`${VIEWLET} .search-widget .replace-container .monaco-inputbox input[title="Replace"]`); + await this.spectron.client.element(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`); + await this.spectron.client.setValue(`${VIEWLET} .search-widget .replace-container .monaco-inputbox.synthetic-focus input[title="Replace"]`, text); } - public async replaceFileMatch(index: number): Promise { - await this.spectron.client.waitAndmoveToObject(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch`); - await this.spectron.client.click(`${Search.SEARCH_VIEWLET_XPATH} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-replace-all`); + async replaceFileMatch(index: number): Promise { + await this.spectron.client.waitAndMoveToObject(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch`); + await this.spectron.client.click(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-replace-all`); } - public async waitForResultText(text: string): Promise { - await this.spectron.client.waitForText(`${Search.SEARCH_VIEWLET_XPATH} .messages[aria-hidden="false"] .message>p`, text); + async waitForResultText(text: string): Promise { + await this.spectron.client.waitForText(`${VIEWLET} .messages[aria-hidden="false"] .message>p`, text); } } \ No newline at end of file diff --git a/test/smoke/src/areas/statusbar/statusbar.test.ts b/test/smoke/src/areas/statusbar/statusbar.test.ts index 70d91d1557f..9ea1798e130 100644 --- a/test/smoke/src/areas/statusbar/statusbar.test.ts +++ b/test/smoke/src/areas/statusbar/statusbar.test.ts @@ -68,7 +68,7 @@ describe('Statusbar', () => { await app.workbench.quickopen.waitForQuickOpenOpened(); - await app.workbench.quickopen.submit('15'); + await app.workbench.quickopen.submit(':15'); await app.workbench.editor.waitForHighlightingLine(15); }); diff --git a/test/smoke/src/areas/terminal/terminal.ts b/test/smoke/src/areas/terminal/terminal.ts index eff9e3a2594..951497edccf 100644 --- a/test/smoke/src/areas/terminal/terminal.ts +++ b/test/smoke/src/areas/terminal/terminal.ts @@ -9,10 +9,10 @@ const PANEL_SELECTOR = 'div[id="workbench.panel.terminal"]'; const XTERM_SELECTOR = `${PANEL_SELECTOR} .terminal-wrapper`; export class Terminal { - constructor(private spectron: SpectronApplication) { - } - public async showTerminal(): Promise { + constructor(private spectron: SpectronApplication) { } + + async showTerminal(): Promise { if (!await this.isVisible()) { await this.spectron.workbench.quickopen.runCommand('View: Toggle Integrated Terminal'); await this.spectron.client.waitForElement(XTERM_SELECTOR); @@ -20,17 +20,18 @@ export class Terminal { } } - public async isVisible(): Promise { + async isVisible(): Promise { const element = await this.spectron.client.element(PANEL_SELECTOR); return !!element; } - public async runCommand(commandText: string): Promise { - await this.spectron.client.type(commandText); + async runCommand(commandText: string): Promise { + // TODO@Tyriar fix this. we should not use type but setValue + // await this.spectron.client.type(commandText); await this.spectron.client.keys(['Enter', 'NULL']); } - public async waitForTerminalText(fn: (text: string[]) => boolean, timeOutDescription: string = 'Getting Terminal Text'): Promise { + async waitForTerminalText(fn: (text: string[]) => boolean, timeOutDescription: string = 'Getting Terminal Text'): Promise { return this.spectron.client.waitFor(async () => { const terminalText = await this.getTerminalText(); if (fn(terminalText)) { @@ -40,7 +41,7 @@ export class Terminal { }, void 0, timeOutDescription); } - public getCurrentLineNumber(): Promise { + getCurrentLineNumber(): Promise { return this.getTerminalText().then(text => text.length); } diff --git a/test/smoke/src/areas/workbench/data-migration.test.ts b/test/smoke/src/areas/workbench/data-migration.test.ts index cb217fc46be..d52859bc1ae 100644 --- a/test/smoke/src/areas/workbench/data-migration.test.ts +++ b/test/smoke/src/areas/workbench/data-migration.test.ts @@ -49,10 +49,9 @@ describe('Data Migration', () => { await Util.removeFile(`${fileName}`); await app.start('Data Migration'); - await app.workbench.waitForActiveTab(fileName); - await app.client.type(firstTextPart); + await app.workbench.editor.waitForTypeInEditor('plainFile', firstTextPart); await app.workbench.saveOpenedFile(); - await app.client.type(secondTextPart); + await app.workbench.editor.waitForTypeInEditor('plainFile', secondTextPart); await app.stop(); await new Promise(c => setTimeout(c, 1000)); // wait until all resources are released (e.g. locked local storage) diff --git a/test/smoke/src/areas/workbench/workbench.ts b/test/smoke/src/areas/workbench/workbench.ts index 9bf860c3584..08a3204d1eb 100644 --- a/test/smoke/src/areas/workbench/workbench.ts +++ b/test/smoke/src/areas/workbench/workbench.ts @@ -57,7 +57,7 @@ export class Workbench { // ignore if there is no dirty file return Promise.resolve(); } - await this.spectron.command('workbench.action.files.save'); + await this.spectron.runCommand('workbench.action.files.save'); return this.spectron.client.waitForElement('.tabs-container div.tab.active.dirty', element => !element); } @@ -71,8 +71,8 @@ export class Workbench { await this.editor.waitForActiveEditor(fileName); } - public async waitForActiveTab(fileName: string, isDirty: boolean = false): Promise { - return this.spectron.client.waitForElement(`.tabs-container div.tab.active${isDirty ? '.dirty' : ''}[aria-selected="true"][aria-label="${fileName}, tab"]`).then(() => true); + public async waitForActiveTab(fileName: string, isDirty: boolean = false): Promise { + return this.spectron.client.waitForElement(`.tabs-container div.tab.active${isDirty ? '.dirty' : ''}[aria-selected="true"][aria-label="${fileName}, tab"]`); } public async waitForTab(fileName: string, isDirty: boolean = false): Promise { @@ -80,7 +80,7 @@ export class Workbench { } public async newUntitledFile(): Promise { - await this.spectron.command('workbench.action.files.newUntitledFile'); + await this.spectron.runCommand('workbench.action.files.newUntitledFile'); await this.waitForEditorFocus('Untitled-1', true); } } diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index 01be7f3f6f2..6b88aed84e8 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -262,7 +262,7 @@ export class SpectronApplication { * Retrieves the command from keybindings file and executes it with WebdriverIO client API * @param command command (e.g. 'workbench.action.files.newUntitledFile') */ - command(command: string, capture?: boolean): Promise { + runCommand(command: string): Promise { const binding = this.keybindings.find(x => x['command'] === command); if (!binding) { return this.workbench.quickopen.runCommand(command); @@ -278,7 +278,7 @@ export class SpectronApplication { keysToPress.push('NULL'); }); - return this.client.keys(keysToPress, capture); + return this.client.keys(keysToPress); } /** diff --git a/test/smoke/src/spectron/client.ts b/test/smoke/src/spectron/client.ts index 324dc9c8a2f..24857764b63 100644 --- a/test/smoke/src/spectron/client.ts +++ b/test/smoke/src/spectron/client.ts @@ -25,7 +25,7 @@ export class SpectronClient { return this.spectron.client.windowByIndex(index); } - keys(keys: string[] | string, capture: boolean = true): Promise { + keys(keys: string[]): Promise { this.spectron.client.keys(keys); return Promise.resolve(); } @@ -78,7 +78,7 @@ export class SpectronClient { return this.spectron.client.moveToObject(selector); } - async waitAndmoveToObject(selector: string): Promise { + async waitAndMoveToObject(selector: string): Promise { return this.waitFor(() => this.spectron.client.moveToObject(selector), void 0, `move to object with selector ${selector}`); } @@ -133,10 +133,6 @@ export class SpectronClient { return Promise.resolve(this.spectron.client.getAttribute(selector, attribute)); } - clearElement(selector: string): any { - return this.spectron.client.clearElement(selector); - } - buttonDown(): any { return this.spectron.client.buttonDown(); } @@ -191,22 +187,22 @@ export class SpectronClient { } } - type(text: string): Promise { - return new Promise((res) => { - let textSplit = text.split(' '); + // type(text: string): Promise { + // return new Promise((res) => { + // let textSplit = text.split(' '); - const type = async (i: number) => { - if (!textSplit[i] || textSplit[i].length <= 0) { - return res(); - } + // const type = async (i: number) => { + // if (!textSplit[i] || textSplit[i].length <= 0) { + // return res(); + // } - const toType = textSplit[i + 1] ? `${textSplit[i]} ` : textSplit[i]; - await this.keys(toType, false); - await this.keys(['NULL']); - await type(i + 1); - }; + // const toType = textSplit[i + 1] ? `${textSplit[i]} ` : textSplit[i]; + // await this.keys(toType); + // await this.keys(['NULL']); + // await type(i + 1); + // }; - return type(0); - }); - } + // return type(0); + // }); + // } } \ No newline at end of file