提交 713e5c13 编写于 作者: J Joao Moreno

screenshot support

上级 66581ee3
......@@ -27,6 +27,7 @@ export interface IDriver {
_serviceBrand: any;
getWindowIds(): TPromise<number[]>;
capturePage(windowId: number): TPromise<string>;
reloadWindow(windowId: number): TPromise<void>;
dispatchKeybinding(windowId: number, keybinding: string): TPromise<void>;
click(windowId: number, selector: string, xoffset?: number | undefined, yoffset?: number | undefined): TPromise<void>;
......@@ -43,6 +44,7 @@ export interface IDriver {
export interface IDriverChannel extends IChannel {
call(command: 'getWindowIds'): TPromise<number[]>;
call(command: 'capturePage'): TPromise<string>;
call(command: 'reloadWindow', arg: number): TPromise<void>;
call(command: 'dispatchKeybinding', arg: [number, string]): TPromise<void>;
call(command: 'click', arg: [number, string, number | undefined, number | undefined]): TPromise<void>;
......@@ -64,6 +66,7 @@ export class DriverChannel implements IDriverChannel {
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'getWindowIds': return this.driver.getWindowIds();
case 'capturePage': return this.driver.capturePage(arg);
case 'reloadWindow': return this.driver.reloadWindow(arg);
case 'dispatchKeybinding': return this.driver.dispatchKeybinding(arg[0], arg[1]);
case 'click': return this.driver.click(arg[0], arg[1], arg[2], arg[3]);
......@@ -91,6 +94,10 @@ export class DriverChannelClient implements IDriver {
return this.channel.call('getWindowIds');
}
capturePage(windowId: number): TPromise<string> {
return this.channel.call('capturePage', windowId);
}
reloadWindow(windowId: number): TPromise<void> {
return this.channel.call('reloadWindow', windowId);
}
......
......@@ -20,6 +20,7 @@ import { Emitter, toPromise } from 'vs/base/common/event';
// TODO@joao: bad layering!
import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO';
import { ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
import { NativeImage } from 'electron';
class WindowRouter implements IClientRouter {
......@@ -63,6 +64,17 @@ export class Driver implements IDriver, IWindowDriverRegistry {
.filter(id => this.registeredWindowIds.has(id) && !this.reloadingWindowIds.has(id));
}
async capturePage(windowId: number): TPromise<string> {
await this.whenUnfrozen(windowId);
const window = this.windowsService.getWindowById(windowId);
const webContents = window.win.webContents;
const image = await new Promise<NativeImage>(c => webContents.capturePage(c));
const buffer = image.toPNG();
return buffer.toString('base64');
}
async reloadWindow(windowId: number): TPromise<void> {
await this.whenUnfrozen(windowId);
......
......@@ -93,6 +93,10 @@ export class Application {
}
}
async capturePage(): Promise<string> {
return this.code.capturePage();
}
private async startApplication(workspaceOrFolder: string, extraArgs: string[] = []): Promise<any> {
this._code = await spawn({
codePath: this.options.codePath,
......
......@@ -38,7 +38,8 @@ const opts = minimist(args, {
'stable-build',
'wait-time',
'test-repo',
'keybindings'
'keybindings',
'screenshots'
],
boolean: [
'verbose'
......@@ -55,6 +56,12 @@ const keybindingsPath = path.join(testDataPath, 'keybindings.json');
const extensionsPath = path.join(testDataPath, 'extensions-dir');
mkdirp.sync(extensionsPath);
const screenshotsPath = opts.screenshots ? path.resolve(opts.screenshots) : null;
if (screenshotsPath) {
mkdirp.sync(screenshotsPath);
}
function fail(errorMessage): void {
console.error(errorMessage);
process.exit(1);
......@@ -256,7 +263,7 @@ describe('Data Migration', () => {
setupDataMigrationTests(userDataDir, createApp);
});
describe('Everything Else', () => {
describe('Test', () => {
before(async function () {
const app = createApp(quality);
await app!.start();
......@@ -267,6 +274,22 @@ describe('Everything Else', () => {
await this.app.stop();
});
if (screenshotsPath) {
afterEach(async function () {
if (this.currentTest.state !== 'failed') {
return;
}
const app = this.app as Application;
const raw = await app.capturePage();
const buffer = new Buffer(raw, 'base64');
const name = this.currentTest.fullTitle().replace(/[^a-z0-9\-]/ig, '_');
const screenshotPath = path.join(screenshotsPath, `${name}.png`);
fs.writeFileSync(screenshotPath, buffer);
});
}
setupDataLossTests();
setupDataExplorerTests();
setupDataPreferencesTests();
......
......@@ -202,6 +202,11 @@ export class Code {
}
}
async capturePage(): Promise<string> {
const windowId = await this.getActiveWindowId();
return await this.driver.capturePage(windowId);
}
async waitForWindowIds(fn: (windowIds: number[]) => boolean): Promise<void> {
await poll(() => this.driver.getWindowIds(), fn, `get window ids`);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册