test: drop usages of keys() for typing

This commit is contained in:
Joao Moreno
2017-10-10 14:18:55 +02:00
parent a05536bbf6
commit bffbd01047
25 changed files with 182 additions and 251 deletions
+2 -2
View File
@@ -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');
+2 -2
View File
@@ -41,7 +41,7 @@ export class Debug extends Viewlet {
}
async openDebugViewlet(): Promise<any> {
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<void> {
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']);
+2 -9
View File
@@ -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 () {
+42 -26
View File
@@ -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<QuickOutline> {
async openOutline(): Promise<QuickOutline> {
const outline = new QuickOutline(this.spectron);
await outline.open();
return outline;
}
public async findReferences(term: string, line: number): Promise<References> {
async findReferences(term: string, line: number): Promise<References> {
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<Rename> {
await this.clickOnTerm(term, line);
async rename(filename: string, line: number, from: string, to: string): Promise<void> {
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<void> {
async gotoDefinition(term: string, line: number): Promise<void> {
await this.clickOnTerm(term, line);
await this.spectron.workbench.quickopen.runCommand('Go to Definition');
}
public async peekDefinition(term: string, line: number): Promise<References> {
async peekDefinition(term: string, line: number): Promise<References> {
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<void> {
async waitForHighlightingLine(line: number): Promise<void> {
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<string> {
async getSelector(term: string, line: number): Promise<string> {
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<any> {
async foldAtLine(line: number): Promise<any> {
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<any> {
async unfoldAtLine(line: number): Promise<any> {
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<void> {
async waitUntilHidden(line: number): Promise<void> {
await this.spectron.client.waitFor<number>(() => this.getViewLineIndexWithoutWait(line), lineNumber => lineNumber === undefined, 'Waiting until line number is hidden');
}
public async waitUntilShown(line: number): Promise<void> {
async waitUntilShown(line: number): Promise<void> {
await this.getViewLineIndex(line);
}
public async clickOnTerm(term: string, line: number): Promise<void> {
async clickOnTerm(term: string, line: number): Promise<void> {
const selector = await this.getSelector(term, line);
await this.spectron.client.waitAndClick(selector);
}
public async waitForTypeInEditor(filename: string, text: string): Promise<any> {
const editor = `.monaco-editor[data-uri$="${filename}"]`;
await this.spectron.client.waitAndClick(editor);
async waitForTypeInEditor(filename: string, text: string, selectorPrefix = ''): Promise<any> {
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<any> {
const selector = `.monaco-editor[data-uri$="${filename}"] .view-lines`;
async waitForEditorContents(filename: string, accept: (contents: string) => boolean, selectorPrefix = ''): Promise<any> {
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<any> {
async waitForActiveEditor(filename: string): Promise<any> {
const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`;
return this.spectron.client.waitForActiveElement(selector);
}
// public async waitForActiveEditorFirstLineText(filename: string): Promise<string> {
// async waitForActiveEditorFirstLineText(filename: string): Promise<string> {
// const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`;
// const result = await this.spectron.client.waitFor(
// () => this.spectron.client.spectron.client.execute(s => {
+1 -1
View File
@@ -14,7 +14,7 @@ export class QuickOutline extends QuickOpen {
public async open(): Promise<void> {
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');
-26
View File
@@ -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<void> {
await this.spectron.client.waitForVisibility(Rename.RENAME_BOX);
await this.spectron.client.waitForValue(Rename.RENAME_INPUT, this.term);
}
public async rename(newTerm: string): Promise<void> {
await this.spectron.client.type(newTerm);
await this.spectron.client.keys(['Enter', 'NULL']);
await this.spectron.client.waitForVisibility(Rename.RENAME_BOX, result => !result);
}
}
@@ -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']);
});
+1 -1
View File
@@ -17,7 +17,7 @@ export class Explorer extends Viewlet {
}
public openExplorerView(): Promise<any> {
return this.spectron.command('workbench.view.explorer');
return this.spectron.runCommand('workbench.view.explorer');
}
public getOpenEditorsViewTitle(): Promise<string> {
@@ -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<any> {
await this.spectron.command('workbench.view.extensions');
await this.spectron.runCommand('workbench.view.extensions');
await this.waitForExtensionsViewlet();
}
async waitForExtensionsViewlet(): Promise<any> {
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<any> {
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<boolean> {
+2 -2
View File
@@ -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();
+5 -4
View File
@@ -30,7 +30,7 @@ export class SCM extends Viewlet {
}
async openSCMViewlet(): Promise<any> {
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<void> {
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);
}
}
@@ -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();
+11 -23
View File
@@ -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<void> {
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<any> {
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<void> {
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<any> {
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<any> {
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}."]`);
}
}
@@ -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.');
+13 -17
View File
@@ -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<void> {
await this.spectron.command('workbench.action.openGlobalSettings');
await this.spectron.client.waitForActiveElement('.settings-search-input input');
}
async focusEditableSettings(): Promise<void> {
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<void> {
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');
}
}
+2 -2
View File
@@ -20,14 +20,14 @@ export class Problems {
public async showProblemsView(): Promise<any> {
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<any> {
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);
}
}
+9 -18
View File
@@ -15,28 +15,22 @@ export class QuickOpen {
constructor(readonly spectron: SpectronApplication) { }
async openQuickOpen(): Promise<void> {
await this.spectron.command('workbench.action.quickOpen');
async openQuickOpen(value: string): Promise<void> {
await this.spectron.runCommand('workbench.action.quickOpen');
await this.waitForQuickOpenOpened();
}
async openCommandPallette(): Promise<void> {
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<void> {
await this.spectron.command('workbench.action.closeQuickOpen');
await this.spectron.runCommand('workbench.action.closeQuickOpen');
await this.waitForQuickOpenClosed();
}
async type(text: string): Promise<void> {
await this.spectron.client.type(text);
}
async openFile(fileName: string): Promise<void> {
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<void> {
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<void> {
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();
}
+2 -8
View File
@@ -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');
+42 -55
View File
@@ -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<any> {
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<any> {
await this.spectron.runCommand('workbench.view.search');
await this.spectron.client.waitForActiveElement(INPUT);
}
public async isSearchViewletFocused(): Promise<boolean> {
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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
async showQueryDetails(): Promise<void> {
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<void> {
async hideQueryDetails(): Promise<void> {
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<boolean> {
const element = await this.spectron.client.element(`${Search.SEARCH_VIEWLET_XPATH} .query-details.more`);
async areDetailsVisible(): Promise<boolean> {
const element = await this.spectron.client.element(`${VIEWLET} .query-details.more`);
return !!element;
}
public async removeFileMatch(index: number): Promise<void> {
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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
await this.spectron.client.waitForText(`${Search.SEARCH_VIEWLET_XPATH} .messages[aria-hidden="false"] .message>p`, text);
async waitForResultText(text: string): Promise<void> {
await this.spectron.client.waitForText(`${VIEWLET} .messages[aria-hidden="false"] .message>p`, text);
}
}
@@ -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);
});
+9 -8
View File
@@ -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<void> {
constructor(private spectron: SpectronApplication) { }
async showTerminal(): Promise<void> {
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<boolean> {
async isVisible(): Promise<boolean> {
const element = await this.spectron.client.element(PANEL_SELECTOR);
return !!element;
}
public async runCommand(commandText: string): Promise<void> {
await this.spectron.client.type(commandText);
async runCommand(commandText: string): Promise<void> {
// 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<string[]> {
async waitForTerminalText(fn: (text: string[]) => boolean, timeOutDescription: string = 'Getting Terminal Text'): Promise<string[]> {
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<number> {
getCurrentLineNumber(): Promise<number> {
return this.getTerminalText().then(text => text.length);
}
@@ -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)
+4 -4
View File
@@ -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<boolean> {
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<any> {
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<boolean> {
@@ -80,7 +80,7 @@ export class Workbench {
}
public async newUntitledFile(): Promise<void> {
await this.spectron.command('workbench.action.files.newUntitledFile');
await this.spectron.runCommand('workbench.action.files.newUntitledFile');
await this.waitForEditorFocus('Untitled-1', true);
}
}
+2 -2
View File
@@ -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<any> {
runCommand(command: string): Promise<any> {
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);
}
/**
+17 -21
View File
@@ -25,7 +25,7 @@ export class SpectronClient {
return this.spectron.client.windowByIndex(index);
}
keys(keys: string[] | string, capture: boolean = true): Promise<void> {
keys(keys: string[]): Promise<void> {
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<any> {
async waitAndMoveToObject(selector: string): Promise<any> {
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<any> {
return new Promise((res) => {
let textSplit = text.split(' ');
// type(text: string): Promise<any> {
// 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);
// });
// }
}