提交 04cb8618 编写于 作者: J Joao Moreno

remove screenCapturer

上级 6ec806c6
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ScreenCapturer } from './helpers/screenshot';
import { Driver, Element } from './driver'; import { Driver, Element } from './driver';
export class API { export class API {
...@@ -15,7 +14,6 @@ export class API { ...@@ -15,7 +14,6 @@ export class API {
constructor( constructor(
private driver: Driver, private driver: Driver,
private screenCapturer: ScreenCapturer,
waitTime: number waitTime: number
) { ) {
this.retryCount = (waitTime * 1000) / this.retryDuration; this.retryCount = (waitTime * 1000) / this.retryDuration;
...@@ -99,7 +97,6 @@ export class API { ...@@ -99,7 +97,6 @@ export class API {
while (true) { while (true) {
if (trial > retryCount) { if (trial > retryCount) {
await this.screenCapturer.capture('timeout');
throw new Error(`${timeoutMessage}: Timed out after ${(retryCount * this.retryDuration) / 1000} seconds.`); throw new Error(`${timeoutMessage}: Timed out after ${(retryCount * this.retryDuration) / 1000} seconds.`);
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { API } from './api'; import { API } from './api';
import { ScreenCapturer } from './helpers/screenshot';
import { Workbench } from './areas/workbench/workbench'; import { Workbench } from './areas/workbench/workbench';
import * as fs from 'fs'; import * as fs from 'fs';
import * as cp from 'child_process'; import * as cp from 'child_process';
...@@ -36,7 +35,6 @@ export class SpectronApplication { ...@@ -36,7 +35,6 @@ export class SpectronApplication {
private _api: API; private _api: API;
private _workbench: Workbench; private _workbench: Workbench;
private _screenCapturer: ScreenCapturer;
private codeInstance: Code | undefined; private codeInstance: Code | undefined;
private keybindings: any[]; private keybindings: any[];
private stopLogCollection: (() => Promise<void>) | undefined; private stopLogCollection: (() => Promise<void>) | undefined;
...@@ -53,10 +51,6 @@ export class SpectronApplication { ...@@ -53,10 +51,6 @@ export class SpectronApplication {
return this._api; return this._api;
} }
get screenCapturer(): ScreenCapturer {
return this._screenCapturer;
}
get workbench(): Workbench { get workbench(): Workbench {
return this._workbench; return this._workbench;
} }
...@@ -81,7 +75,6 @@ export class SpectronApplication { ...@@ -81,7 +75,6 @@ export class SpectronApplication {
set suiteName(suiteName: string) { set suiteName(suiteName: string) {
this._suiteName = suiteName; this._suiteName = suiteName;
this._screenCapturer.suiteName = suiteName;
} }
async start(waitForWelcome: boolean = true): Promise<any> { async start(waitForWelcome: boolean = true): Promise<any> {
...@@ -135,10 +128,8 @@ export class SpectronApplication { ...@@ -135,10 +128,8 @@ export class SpectronApplication {
verbose: this.options.verbose verbose: this.options.verbose
}); });
this._screenCapturer = new ScreenCapturer(null as any, this._suiteName, '');
const driver = new CodeDriver(this.codeInstance.driver, this.options.verbose); const driver = new CodeDriver(this.codeInstance.driver, this.options.verbose);
this._api = new API(driver, this.screenCapturer, this.options.waitTime); this._api = new API(driver, this.options.waitTime);
this._workbench = new Workbench(this._api, this.keybindings, this.userDataPath); this._workbench = new Workbench(this._api, this.keybindings, this.userDataPath);
} }
......
...@@ -26,11 +26,9 @@ export function setup() { ...@@ -26,11 +26,9 @@ export function setup() {
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}'); await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');
await app.api.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.WARNING)); await app.api.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.WARNING));
await app.screenCapturer.capture('CSS Warning in editor');
await app.workbench.problems.showProblemsView(); await app.workbench.problems.showProblemsView();
await app.api.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.WARNING)); await app.api.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.WARNING));
await app.screenCapturer.capture('CSS Warning in problems view');
await app.workbench.problems.hideProblemsView(); await app.workbench.problems.hideProblemsView();
}); });
...@@ -41,12 +39,10 @@ export function setup() { ...@@ -41,12 +39,10 @@ export function setup() {
await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}'); await app.workbench.editor.waitForTypeInEditor('style.css', '.foo{}');
await app.api.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.ERROR)); await app.api.waitForElement(Problems.getSelectorInEditor(ProblemSeverity.ERROR));
await app.screenCapturer.capture('CSS Error in editor');
const problems = new Problems(app.api, app.workbench); const problems = new Problems(app.api, app.workbench);
await problems.showProblemsView(); await problems.showProblemsView();
await app.api.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.ERROR)); await app.api.waitForElement(Problems.getSelectorInProblemsView(ProblemSeverity.ERROR));
await app.screenCapturer.capture('CSS Error in probles view');
await problems.hideProblemsView(); await problems.hideProblemsView();
}); });
}); });
......
...@@ -31,7 +31,6 @@ export function setup() { ...@@ -31,7 +31,6 @@ export function setup() {
fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8'); fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8');
await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents)); await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents));
await app.screenCapturer.capture('launch.json file');
assert.equal(config.configurations[0].request, 'launch'); assert.equal(config.configurations[0].request, 'launch');
assert.equal(config.configurations[0].type, 'node'); assert.equal(config.configurations[0].type, 'node');
...@@ -47,7 +46,6 @@ export function setup() { ...@@ -47,7 +46,6 @@ export function setup() {
await app.workbench.quickopen.openFile('index.js'); await app.workbench.quickopen.openFile('index.js');
await app.workbench.debug.setBreakpointOnLine(6); await app.workbench.debug.setBreakpointOnLine(6);
await app.screenCapturer.capture('breakpoints are set');
}); });
let port: number; let port: number;
...@@ -58,15 +56,12 @@ export function setup() { ...@@ -58,15 +56,12 @@ export function setup() {
await new Promise(c => setTimeout(c, 100)); await new Promise(c => setTimeout(c, 100));
port = await app.workbench.debug.startDebugging(); port = await app.workbench.debug.startDebugging();
await app.screenCapturer.capture('debugging has started');
await new Promise((c, e) => { await new Promise((c, e) => {
const request = http.get(`http://localhost:${port}`); const request = http.get(`http://localhost:${port}`);
request.on('error', e); request.on('error', e);
app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6, 'looking for index.js and line 6').then(c, e); app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6, 'looking for index.js and line 6').then(c, e);
}); });
await app.screenCapturer.capture('debugging is paused');
}); });
it('focus stack frames and variables', async function () { it('focus stack frames and variables', async function () {
...@@ -88,15 +83,12 @@ export function setup() { ...@@ -88,15 +83,12 @@ export function setup() {
const app = this.app as SpectronApplication; const app = this.app as SpectronApplication;
await app.workbench.debug.stepIn(); await app.workbench.debug.stepIn();
await app.screenCapturer.capture('debugging has stepped in');
const first = await app.workbench.debug.waitForStackFrame(sf => sf.name === 'response.js', 'looking for response.js'); const first = await app.workbench.debug.waitForStackFrame(sf => sf.name === 'response.js', 'looking for response.js');
await app.workbench.debug.stepOver(); await app.workbench.debug.stepOver();
await app.screenCapturer.capture('debugging has stepped over');
await app.workbench.debug.waitForStackFrame(sf => sf.name === 'response.js' && sf.lineNumber === first.lineNumber + 1, `looking for response.js and line ${first.lineNumber + 1}`); await app.workbench.debug.waitForStackFrame(sf => sf.name === 'response.js' && sf.lineNumber === first.lineNumber + 1, `looking for response.js and line ${first.lineNumber + 1}`);
await app.workbench.debug.stepOut(); await app.workbench.debug.stepOut();
await app.screenCapturer.capture('debugging has stepped out');
await app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 7, `looking for index.js and line 7`); await app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 7, `looking for index.js and line 7`);
}); });
...@@ -105,7 +97,6 @@ export function setup() { ...@@ -105,7 +97,6 @@ export function setup() {
const app = this.app as SpectronApplication; const app = this.app as SpectronApplication;
await app.workbench.debug.continue(); await app.workbench.debug.continue();
await app.screenCapturer.capture('debugging has continued');
await new Promise((c, e) => { await new Promise((c, e) => {
const request = http.get(`http://localhost:${port}`); const request = http.get(`http://localhost:${port}`);
...@@ -113,7 +104,6 @@ export function setup() { ...@@ -113,7 +104,6 @@ export function setup() {
app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6, `looking for index.js and line 6`).then(c, e); app.workbench.debug.waitForStackFrame(sf => sf.name === 'index.js' && sf.lineNumber === 6, `looking for index.js and line 6`).then(c, e);
}); });
await app.screenCapturer.capture('debugging is paused');
}); });
it('debug console', async function () { it('debug console', async function () {
...@@ -126,7 +116,6 @@ export function setup() { ...@@ -126,7 +116,6 @@ export function setup() {
const app = this.app as SpectronApplication; const app = this.app as SpectronApplication;
await app.workbench.debug.stopDebugging(); await app.workbench.debug.stopDebugging();
await app.screenCapturer.capture('debugging has stopped');
}); });
}); });
} }
\ No newline at end of file
...@@ -35,7 +35,6 @@ export function setup() { ...@@ -35,7 +35,6 @@ export function setup() {
await app.workbench.quickopen.openFile('www'); await app.workbench.quickopen.openFile('www');
await app.workbench.editor.rename('www', 7, 'app', 'newApp'); await app.workbench.editor.rename('www', 7, 'app', 'newApp');
await app.workbench.editor.waitForEditorContents('www', contents => contents.indexOf('newApp') > -1); await app.workbench.editor.waitForEditorContents('www', contents => contents.indexOf('newApp') > -1);
await app.screenCapturer.capture('Rename result');
}); });
// it('folds/unfolds the code correctly', async function () { // it('folds/unfolds the code correctly', async function () {
......
...@@ -31,7 +31,6 @@ export function setup() { ...@@ -31,7 +31,6 @@ export function setup() {
await app.workbench.runCommand('Smoke Test Check'); await app.workbench.runCommand('Smoke Test Check');
const statusbarText = await app.workbench.statusbar.getStatusbarTextByTitle('smoke test'); const statusbarText = await app.workbench.statusbar.getStatusbarTextByTitle('smoke test');
await app.screenCapturer.capture('Statusbar');
assert.equal(statusbarText, 'VS Code Smoke Test Check'); assert.equal(statusbarText, 'VS Code Smoke Test Check');
}); });
}); });
......
...@@ -32,7 +32,6 @@ export function setup() { ...@@ -32,7 +32,6 @@ export function setup() {
await app.workbench.scm.refreshSCMViewlet(); await app.workbench.scm.refreshSCMViewlet();
await app.workbench.scm.waitForChange('app.js', 'Modified'); await app.workbench.scm.waitForChange('app.js', 'Modified');
await app.workbench.scm.waitForChange('index.jade', 'Modified'); await app.workbench.scm.waitForChange('index.jade', 'Modified');
await app.screenCapturer.capture('changes');
}); });
it('opens diff editor', async function () { it('opens diff editor', async function () {
......
...@@ -30,7 +30,6 @@ export function setup() { ...@@ -30,7 +30,6 @@ export function setup() {
it('shows workspace name in title', async function () { it('shows workspace name in title', async function () {
const app = this.app as SpectronApplication; const app = this.app as SpectronApplication;
const title = await app.api.getTitle(); const title = await app.api.getTitle();
await app.screenCapturer.capture('window title');
assert.ok(title.indexOf('smoketest (Workspace)') >= 0); assert.ok(title.indexOf('smoketest (Workspace)') >= 0);
}); });
}); });
......
...@@ -19,13 +19,10 @@ export function setup() { ...@@ -19,13 +19,10 @@ export function setup() {
await app.workbench.explorer.openFile('app.js'); await app.workbench.explorer.openFile('app.js');
await app.api.waitForElements('.line-numbers', false, elements => !!elements.length); await app.api.waitForElements('.line-numbers', false, elements => !!elements.length);
await app.screenCapturer.capture('app.js has line numbers');
await app.workbench.settingsEditor.addUserSetting('editor.lineNumbers', '"off"'); await app.workbench.settingsEditor.addUserSetting('editor.lineNumbers', '"off"');
await app.workbench.editors.selectTab('app.js'); await app.workbench.editors.selectTab('app.js');
await app.api.waitForElements('.line-numbers', false, result => !result || result.length === 0); await app.api.waitForElements('.line-numbers', false, result => !result || result.length === 0);
await app.screenCapturer.capture('line numbers hidden');
}); });
it(`changes 'workbench.action.toggleSidebarPosition' command key binding and verifies it`, async function () { it(`changes 'workbench.action.toggleSidebarPosition' command key binding and verifies it`, async function () {
......
...@@ -18,24 +18,19 @@ export function setup() { ...@@ -18,24 +18,19 @@ export function setup() {
const untitled = 'Untitled-1'; const untitled = 'Untitled-1';
const textToTypeInUntitled = 'Hello, Unitled Code'; const textToTypeInUntitled = 'Hello, Unitled Code';
await app.workbench.editor.waitForTypeInEditor(untitled, textToTypeInUntitled); await app.workbench.editor.waitForTypeInEditor(untitled, textToTypeInUntitled);
await app.screenCapturer.capture('Untitled file before reload');
const readmeMd = 'readme.md'; const readmeMd = 'readme.md';
const textToType = 'Hello, Code'; const textToType = 'Hello, Code';
await app.workbench.explorer.openFile(readmeMd); await app.workbench.explorer.openFile(readmeMd);
await app.workbench.editor.waitForTypeInEditor(readmeMd, textToType); await app.workbench.editor.waitForTypeInEditor(readmeMd, textToType);
await app.screenCapturer.capture(`${readmeMd} before reload`);
await app.reload(); await app.reload();
await app.screenCapturer.capture('After reload');
await app.workbench.editors.waitForActiveTab(readmeMd, true); await app.workbench.editors.waitForActiveTab(readmeMd, true);
await app.screenCapturer.capture(`${readmeMd} after reload`);
await app.workbench.editor.waitForEditorContents(readmeMd, c => c.indexOf(textToType) > -1); await app.workbench.editor.waitForEditorContents(readmeMd, c => c.indexOf(textToType) > -1);
await app.workbench.editors.waitForTab(untitled, true); await app.workbench.editors.waitForTab(untitled, true);
await app.workbench.editors.selectTab(untitled, true); await app.workbench.editors.selectTab(untitled, true);
await app.screenCapturer.capture('Untitled file after reload');
await app.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1); await app.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1);
}); });
}); });
......
...@@ -51,7 +51,6 @@ export function setup(userDataDir: string, createApp: ICreateAppFn) { ...@@ -51,7 +51,6 @@ export function setup(userDataDir: string, createApp: ICreateAppFn) {
assert.ok(await app.workbench.editors.waitForActiveTab('Untitled-1', true), `Untitled-1 tab is not present after migration.`); assert.ok(await app.workbench.editors.waitForActiveTab('Untitled-1', true), `Untitled-1 tab is not present after migration.`);
await app.workbench.editor.waitForEditorContents('Untitled-1', c => c.indexOf(textToType) > -1); await app.workbench.editor.waitForEditorContents('Untitled-1', c => c.indexOf(textToType) > -1);
await app.screenCapturer.capture('Untitled file text');
await app.stop(); await app.stop();
}); });
......
...@@ -29,27 +29,22 @@ export function setup() { ...@@ -29,27 +29,22 @@ export function setup() {
} }
let text = await app.workbench.explorer.getOpenEditorsViewTitle(); let text = await app.workbench.explorer.getOpenEditorsViewTitle();
await app.screenCapturer.capture('Open editors title');
assert(/geöffnete editoren/i.test(text)); assert(/geöffnete editoren/i.test(text));
await app.workbench.search.openSearchViewlet(); await app.workbench.search.openSearchViewlet();
text = await app.workbench.search.getTitle(); text = await app.workbench.search.getTitle();
await app.screenCapturer.capture('Search title');
assert(/suchen/i.test(text)); assert(/suchen/i.test(text));
await app.workbench.scm.openSCMViewlet(); await app.workbench.scm.openSCMViewlet();
text = await app.workbench.scm.getTitle(); text = await app.workbench.scm.getTitle();
await app.screenCapturer.capture('Scm title');
assert(/quellcodeverwaltung/i.test(text)); assert(/quellcodeverwaltung/i.test(text));
await app.workbench.debug.openDebugViewlet(); await app.workbench.debug.openDebugViewlet();
text = await app.workbench.debug.getTitle(); text = await app.workbench.debug.getTitle();
await app.screenCapturer.capture('Debug title');
assert(/debuggen/i.test(text)); assert(/debuggen/i.test(text));
await app.workbench.extensions.openExtensionsViewlet(); await app.workbench.extensions.openExtensionsViewlet();
text = await app.workbench.extensions.getTitle(); text = await app.workbench.extensions.getTitle();
await app.screenCapturer.capture('Extensions title');
assert(/erweiterungen/i.test(text)); assert(/erweiterungen/i.test(text));
}); });
}); });
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import { Application } from 'spectron';
import { sanitize } from './utilities';
export class ScreenCapturer {
private static counter = 0;
constructor(
private application: Application,
public suiteName: string,
private screenshotsDirPath: string | undefined,
) { }
async capture(name: string): Promise<void> {
if (!this.screenshotsDirPath) {
return;
}
const screenshotPath = path.join(
this.screenshotsDirPath,
sanitize(this.suiteName),
`${ScreenCapturer.counter++}-${sanitize(name)}.png`
);
const image = await this.application.browserWindow.capturePage();
await new Promise((c, e) => mkdirp(path.dirname(screenshotPath), err => err ? e(err) : c()));
await new Promise((c, e) => fs.writeFile(screenshotPath, image, err => err ? e(err) : c()));
}
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as fs from 'fs';
import { dirname } from 'path';
export function nfcall<R>(fn: Function, ...args): Promise<R> {
return new Promise<R>((c, e) => fn(...args, (err, r) => err ? e(err) : c(r)));
}
export async function mkdirp(path: string, mode?: number): Promise<boolean> {
const mkdir = async () => {
try {
await nfcall(fs.mkdir, path, mode);
} catch (err) {
if (err.code === 'EEXIST') {
const stat = await nfcall<fs.Stats>(fs.stat, path);
if (stat.isDirectory) {
return;
}
throw new Error(`'${path}' exists and is not a directory.`);
}
throw err;
}
};
// is root?
if (path === dirname(path)) {
return true;
}
try {
await mkdir();
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
await mkdirp(dirname(path), mode);
await mkdir();
}
return true;
}
export function sanitize(name: string): string {
return name.replace(/[&*:\/]/g, '');
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册