提交 225d7e5a 编写于 作者: J Joao Moreno

cleanup API

上级 36be36db
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Element } from 'webdriverio';
import { SpectronApplication } from '../../spectron/application';
export enum ActivityBarPosition {
......@@ -17,7 +16,7 @@ export class ActivityBar {
// noop
}
public async getActivityBar(position: ActivityBarPosition): Promise<Element> {
public async getActivityBar(position: ActivityBarPosition): Promise<void> {
let positionClass: string;
if (position === ActivityBarPosition.LEFT) {
......
......@@ -3,7 +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';
import { ProblemSeverity, Problems } from '../problems/problems';
......@@ -26,14 +25,12 @@ export function setup() {
await app.workbench.quickopen.openFile('style.css');
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');
let warning = await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.WARNING));
await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.WARNING));
await app.screenCapturer.capture('CSS Warning in editor');
assert.ok(warning, `Warning squiggle is not shown in 'style.css'.`);
await app.workbench.problems.showProblemsView();
warning = await app.client.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.WARNING));
await app.client.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.WARNING));
await app.screenCapturer.capture('CSS Warning in problems view');
assert.ok(warning, 'Warning does not appear in Problems view.');
await app.workbench.problems.hideProblemsView();
});
......@@ -43,15 +40,13 @@ export function setup() {
await app.workbench.quickopen.openFile('style.css');
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');
let error = await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.ERROR));
await app.client.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.ERROR));
await app.screenCapturer.capture('CSS Error in editor');
assert.ok(error, `Warning squiggle is not shown in 'style.css'.`);
const problems = new Problems(app);
await problems.showProblemsView();
error = await app.client.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.ERROR));
await app.client.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.ERROR));
await app.screenCapturer.capture('CSS Error in probles view');
assert.ok(error, 'Warning does not appear in Problems view.');
await problems.hideProblemsView();
});
});
......
......@@ -52,7 +52,7 @@ export class Debug extends Viewlet {
async setBreakpointOnLine(lineNumber: number): Promise<any> {
await this.spectron.client.waitForElement(`${GLYPH_AREA}(${lineNumber})`);
await this.spectron.client.leftClick(`${GLYPH_AREA}(${lineNumber})`, 5, 5);
await this.spectron.client.waitAndClick(`${GLYPH_AREA}(${lineNumber})`, 5, 5);
await this.spectron.client.waitForElement(BREAKPOINT_GLYPH);
}
......
......@@ -103,7 +103,7 @@ export class Editor {
`.monaco-editor[data-uri$="${filename}"]`
].join(' ');
await this.spectron.client.element(editor);
await this.spectron.client.waitForElement(editor);
const textarea = `${editor} textarea`;
await this.spectron.client.waitForActiveElement(textarea);
......@@ -174,7 +174,8 @@ export class Editor {
const result: { text: string, className: string }[] = await this.spectron.webclient.selectorExecute(`${Editor.VIEW_LINES}>:nth-child(${viewline}) span span`,
elements => (Array.isArray(elements) ? elements : [elements])
.map(element => ({ text: element.textContent, className: element.className })));
return result.filter(r => r.text === term).map(({ className }) => className);
const { className } = result.filter(r => r.text === term)[0];
return className.split(/\s/g);
}
private async getViewLineIndex(line: number): Promise<number> {
......
......@@ -3,26 +3,24 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { SpectronApplication } from '../../spectron/application';
import { QuickOpen } from '../quickopen/quickopen';
export class QuickOutline extends QuickOpen {
constructor(spectron: SpectronApplication) {
super(spectron);
}
public async open(): Promise<void> {
await this.spectron.client.waitFor(async () => {
let retries = 0;
while (++retries < 10) {
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');
if (text !== 'No symbol information for the file') {
return entry;
}
const text = await this.spectron.client.waitForText('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');
if (text !== 'No symbol information for the file') {
return;
}
await this.closeQuickOpen();
}, undefined, 'Opening Outline');
await new Promise(c => setTimeout(c, 250));
}
}
}
......@@ -25,7 +25,7 @@ export class Explorer extends Viewlet {
}
public async openFile(fileName: string): Promise<any> {
await this.spectron.client.doubleClickAndWait(`div[class="monaco-icon-label file-icon ${fileName}-name-file-icon ${this.getExtensionSelector(fileName)} explorer-item"]`);
await this.spectron.client.waitAndDoubleClick(`div[class="monaco-icon-label file-icon ${fileName}-name-file-icon ${this.getExtensionSelector(fileName)} explorer-item"]`);
await this.spectron.workbench.waitForEditorFocus(fileName);
}
......
......@@ -24,7 +24,7 @@ export class Extensions extends Viewlet {
}
async searchForExtension(name: string): Promise<any> {
await this.spectron.client.click(SEARCH_BOX);
await this.spectron.client.waitAndClick(SEARCH_BOX);
await this.spectron.client.waitForActiveElement(SEARCH_BOX);
await this.spectron.client.setValue(SEARCH_BOX, name);
}
......@@ -34,7 +34,7 @@ export class Extensions extends Viewlet {
// we might want to wait for a while longer since the Marketplace can be slow
// a minute should do
await this.spectron.client.waitFor(() => this.spectron.client.click(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[aria-label="${name}"] .extension li[class='action-item'] .extension-action.install`), void 0, 'waiting for install button', 600);
await this.spectron.client.waitFor(() => this.spectron.client.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[aria-label="${name}"] .extension li[class='action-item'] .extension-action.install`), void 0, 'waiting for install button', 600);
await this.spectron.client.waitForElement(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[aria-label="${name}"] .extension li[class='action-item'] .extension-action.reload`);
return true;
......
......@@ -41,7 +41,7 @@ export class SCM extends Viewlet {
}
async refreshSCMViewlet(): Promise<any> {
await this.spectron.client.click(REFRESH_COMMAND);
await this.spectron.client.waitAndClick(REFRESH_COMMAND);
}
private async queryChanges(name: string, type?: string): Promise<Change[]> {
......
......@@ -18,16 +18,14 @@ export function setup() {
const app = this.app as SpectronApplication;
await app.workbench.explorer.openFile('app.js');
let lineNumbers = await app.client.waitForElements('.line-numbers');
await app.client.waitForElements('.line-numbers', elements => !!elements.length);
await app.screenCapturer.capture('app.js has line numbers');
assert.ok(!!lineNumbers.length, 'Line numbers are not present in the editor before disabling them.');
await app.workbench.settingsEditor.addUserSetting('editor.lineNumbers', '"off"');
await app.workbench.selectTab('app.js');
lineNumbers = await app.client.waitForElements('.line-numbers', result => !result || result.length === 0);
await app.client.waitForElements('.line-numbers', result => !result || result.length === 0);
await app.screenCapturer.capture('line numbers hidden');
assert.ok(!lineNumbers.length, 'Line numbers are still present in the editor after disabling them.');
});
it(`changes 'workbench.action.toggleSidebarPosition' command key binding and verifies it`, async function () {
......
......@@ -32,9 +32,8 @@ export class Problems {
}
}
public async isVisible(): Promise<boolean> {
const element = await this.spectron.client.element(Problems.PROBLEMS_VIEW_SELECTOR);
return !!element;
isVisible(): Promise<boolean> {
return this.spectron.client.doesElementExist(Problems.PROBLEMS_VIEW_SELECTOR);
}
public async waitForProblemsView(): Promise<void> {
......
......@@ -22,22 +22,22 @@ export class Search extends Viewlet {
}
async searchFor(text: string): Promise<void> {
await this.spectron.client.click(INPUT);
await this.spectron.client.waitAndClick(INPUT);
await this.spectron.client.waitForActiveElement(INPUT);
await this.spectron.client.setValue(INPUT, text);
await this.submitSearch();
}
async submitSearch(): Promise<void> {
await this.spectron.client.click(INPUT);
await this.spectron.client.waitAndClick(INPUT);
await this.spectron.client.waitForActiveElement(INPUT);
await this.spectron.client.keys(['Enter', 'NULL']);
await this.spectron.client.element(`${VIEWLET} .messages[aria-hidden="false"]`);
await this.spectron.client.waitForElement(`${VIEWLET} .messages[aria-hidden="false"]`);
}
async setFilesToIncludeText(text: string): Promise<void> {
await this.spectron.client.click(INCLUDE_INPUT);
await this.spectron.client.waitAndClick(INCLUDE_INPUT);
await this.spectron.client.waitForActiveElement(INCLUDE_INPUT);
await this.spectron.client.setValue(INCLUDE_INPUT, text || '');
}
......@@ -54,9 +54,8 @@ export class Search extends Viewlet {
}
}
async areDetailsVisible(): Promise<boolean> {
const element = await this.spectron.client.element(`${VIEWLET} .query-details.more`);
return !!element;
areDetailsVisible(): Promise<boolean> {
return this.spectron.client.doesElementExist(`${VIEWLET} .query-details.more`);
}
async removeFileMatch(index: number): Promise<void> {
......@@ -72,13 +71,13 @@ export class Search extends Viewlet {
async setReplaceText(text: string): Promise<void> {
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.waitForElement(`${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);
}
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`);
await this.spectron.client.waitAndClick(`${VIEWLET} .results .monaco-tree-rows>:nth-child(${index}) .filematch .action-label.icon.action-replace-all`);
}
async waitForResultText(text: string): Promise<void> {
......
......@@ -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, Quality } from '../../spectron/application';
import { StatusBarElement } from './statusbar';
......@@ -69,7 +67,7 @@ export function setup() {
}
await app.workbench.statusbar.clickOn(StatusBarElement.FEEDBACK_ICON);
assert.ok(!!await app.client.waitForElement('.feedback-form'));
await app.client.waitForElement('.feedback-form');
});
it(`checks if 'Go to Line' works if called from the status bar`, async function () {
......
......@@ -20,9 +20,8 @@ export class Terminal {
}
}
async isVisible(): Promise<boolean> {
const element = await this.spectron.client.element(PANEL_SELECTOR);
return !!element;
isVisible(): Promise<boolean> {
return this.spectron.client.doesElementExist(PANEL_SELECTOR);
}
async runCommand(commandText: string): Promise<void> {
......
......@@ -65,12 +65,12 @@ export class Workbench {
await this.editor.waitForActiveEditor(fileName);
}
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 waitForActiveTab(fileName: string, isDirty: boolean = false): Promise<void> {
await 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> {
return this.spectron.client.waitForElement(`.tabs-container div.tab${isDirty ? '.dirty' : ''}[aria-label="${fileName}, tab"]`).then(() => true);
public async waitForTab(fileName: string, isDirty: boolean = false): Promise<void> {
await this.spectron.client.waitForElement(`.tabs-container div.tab${isDirty ? '.dirty' : ''}[aria-label="${fileName}, tab"]`);
}
public async newUntitledFile(): Promise<void> {
......
......@@ -7,9 +7,6 @@ import { Application } from 'spectron';
import { RawResult, Element } from 'webdriverio';
import { SpectronApplication } from './application';
/**
* Abstracts the Spectron's WebdriverIO managed client property on the created Application instances.
*/
export class SpectronClient {
// waitFor calls should not take more than 200 * 100 = 20 seconds to complete, excluding
......@@ -30,10 +27,6 @@ export class SpectronClient {
return Promise.resolve();
}
async getText(selector: string, capture: boolean = true): Promise<any> {
return this.spectron.client.getText(selector);
}
async waitForText(selector: string, text?: string, accept?: (result: string) => boolean): Promise<string> {
accept = accept ? accept : result => text !== void 0 ? text === result : !!result;
return this.waitFor(() => this.spectron.client.getText(selector), accept, `getText with selector ${selector}`);
......@@ -45,35 +38,14 @@ export class SpectronClient {
return this.waitFor(fn, s => accept!(typeof s === 'string' ? s : ''), `getTextContent with selector ${selector}`);
}
async waitForValue(selector: string, value?: string, accept?: (result: string) => boolean): Promise<any> {
accept = accept ? accept : result => value !== void 0 ? value === result : !!result;
return this.waitFor(() => this.spectron.client.getValue(selector), accept, `getValue with selector ${selector}`);
async waitAndClick(selector: string, xoffset?: number, yoffset?: number): Promise<any> {
return this.waitFor(() => this.spectron.client.leftClick(selector, xoffset, yoffset), void 0, `click with selector ${selector}`);
}
async waitAndClick(selector: string): Promise<any> {
return this.waitFor(() => this.spectron.client.click(selector), void 0, `click with selector ${selector}`);
}
async click(selector: string): Promise<any> {
return this.spectron.client.click(selector);
}
async doubleClickAndWait(selector: string, capture: boolean = true): Promise<any> {
async waitAndDoubleClick(selector: string, capture: boolean = true): Promise<any> {
return this.waitFor(() => this.spectron.client.doubleClick(selector), void 0, `doubleClick with selector ${selector}`);
}
async leftClick(selector: string, xoffset: number, yoffset: number, capture: boolean = true): Promise<any> {
return this.spectron.client.leftClick(selector, xoffset, yoffset);
}
async rightClick(selector: string, capture: boolean = true): Promise<any> {
return this.spectron.client.rightClick(selector);
}
async moveToObject(selector: string, capture: boolean = true): Promise<any> {
return this.spectron.client.moveToObject(selector);
}
async waitAndMoveToObject(selector: string): Promise<any> {
return this.waitFor(() => this.spectron.client.moveToObject(selector), void 0, `move to object with selector ${selector}`);
}
......@@ -82,23 +54,16 @@ export class SpectronClient {
return this.spectron.client.setValue(selector, text);
}
async waitForElements(selector: string, accept: (result: Element[]) => boolean = result => result.length > 0): Promise<Element[]> {
return this.waitFor<RawResult<Element[]>>(() => this.spectron.client.elements(selector), result => accept(result.value), `elements with selector ${selector}`)
.then(result => result.value);
}
async waitForElement(selector: string, accept: (result: Element | undefined) => boolean = result => !!result): Promise<Element> {
return this.waitFor<RawResult<Element>>(() => this.spectron.client.element(selector), result => accept(result ? result.value : void 0), `element with selector ${selector}`)
.then(result => result.value);
async doesElementExist(selector: string): Promise<boolean> {
return this.spectron.client.element(selector).then(result => !!result.value);
}
async waitForVisibility(selector: string, accept: (result: boolean) => boolean = result => result): Promise<any> {
return this.waitFor(() => this.spectron.client.isVisible(selector), accept, `isVisible with selector ${selector}`);
async waitForElements(selector: string, accept: (result: Element[]) => boolean = result => result.length > 0): Promise<void> {
return this.waitFor(() => this.spectron.client.elements(selector), result => accept(result.value), `elements with selector ${selector}`) as Promise<any>;
}
async element(selector: string): Promise<Element> {
return this.spectron.client.element(selector)
.then(result => result.value);
async waitForElement(selector: string, accept: (result: Element | undefined) => boolean = result => !!result): Promise<void> {
return this.waitFor<RawResult<Element>>(() => this.spectron.client.element(selector), result => accept(result ? result.value : void 0), `element with selector ${selector}`) as Promise<any>;
}
async waitForActiveElement(selector: string): Promise<any> {
......@@ -109,38 +74,6 @@ export class SpectronClient {
);
}
async waitForAttribute(selector: string, attribute: string, accept: (result: string) => boolean = result => !!result): Promise<string> {
return this.waitFor<string>(() => this.spectron.client.getAttribute(selector), accept, `attribute with selector ${selector}`);
}
async dragAndDrop(sourceElem: string, destinationElem: string, capture: boolean = true): Promise<any> {
return this.spectron.client.dragAndDrop(sourceElem, destinationElem);
}
async selectByValue(selector: string, value: string, capture: boolean = true): Promise<any> {
return this.spectron.client.selectByValue(selector, value);
}
async getValue(selector: string, capture: boolean = true): Promise<any> {
return this.spectron.client.getValue(selector);
}
async getAttribute(selector: string, attribute: string, capture: boolean = true): Promise<any> {
return Promise.resolve(this.spectron.client.getAttribute(selector, attribute));
}
buttonDown(): any {
return this.spectron.client.buttonDown();
}
buttonUp(): any {
return this.spectron.client.buttonUp();
}
async isVisible(selector: string, capture: boolean = true): Promise<any> {
return this.spectron.client.isVisible(selector);
}
async getTitle(): Promise<string> {
return this.spectron.client.getTitle();
}
......@@ -182,23 +115,4 @@ export class SpectronClient {
this.running = false;
}
}
// 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 toType = textSplit[i + 1] ? `${textSplit[i]} ` : textSplit[i];
// await this.keys(toType);
// await this.keys(['NULL']);
// await type(i + 1);
// };
// return type(0);
// });
// }
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册