mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Correct screenshotting logic.
This commit is contained in:
parent
b46e41cb36
commit
836d40adbf
|
@ -20,20 +20,20 @@ export class Screenshot {
|
|||
this.createFolder(this.testPath);
|
||||
}
|
||||
|
||||
public capture(): Promise<any> {
|
||||
public async capture(): Promise<any> {
|
||||
return new Promise(async (res, rej) => {
|
||||
const image: Electron.NativeImage = await this.spectron.app.browserWindow.capturePage();
|
||||
fs.writeFile(`${this.testPath}/${this.index}.png`, image, (err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
}
|
||||
this.index++;
|
||||
res();
|
||||
});
|
||||
this.index++;
|
||||
res();
|
||||
});
|
||||
}
|
||||
|
||||
private createFolder(name: string) {
|
||||
private createFolder(name: string): void {
|
||||
name.split('/').forEach((folderName, i, fullPath) => {
|
||||
const folder = fullPath.slice(0, i + 1).join('/');
|
||||
if (!fs.existsSync(folder)) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import { Application } from 'spectron';
|
|||
import { Screenshot } from '../helpers/screenshot';
|
||||
|
||||
/**
|
||||
* Abstracts the Spectron's WebdriverIO managed client property on the created Application instances.
|
||||
* Abstracts the Spectron's WebdriverIO managed client property on the created Application instances.
|
||||
*/
|
||||
export class SpectronClient {
|
||||
|
||||
|
@ -20,77 +20,77 @@ export class SpectronClient {
|
|||
}
|
||||
|
||||
public async keys(keys: string[] | string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.keys(keys);
|
||||
}
|
||||
|
||||
public async getText(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.getText(selector);
|
||||
}
|
||||
|
||||
public async getHTML(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.getHTML(selector);
|
||||
}
|
||||
|
||||
public async click(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.click(selector);
|
||||
}
|
||||
|
||||
public async doubleClick(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.doubleClick(selector);
|
||||
}
|
||||
|
||||
public async leftClick(selector: string, xoffset: number, yoffset: number, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.leftClick(selector, xoffset, yoffset);
|
||||
}
|
||||
|
||||
public async rightClick(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.rightClick(selector);
|
||||
}
|
||||
|
||||
public async moveToObject(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.moveToObject(selector);
|
||||
}
|
||||
|
||||
public async setValue(selector: string, text: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.setValue(selector, text);
|
||||
}
|
||||
|
||||
public async elements(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.elements(selector);
|
||||
}
|
||||
|
||||
public async element(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.element(selector);
|
||||
}
|
||||
|
||||
public async dragAndDrop(sourceElem: string, destinationElem: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.dragAndDrop(sourceElem, destinationElem);
|
||||
}
|
||||
|
||||
public async selectByValue(selector: string, value: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.selectByValue(selector, value);
|
||||
}
|
||||
|
||||
public async getValue(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.getValue(selector);
|
||||
}
|
||||
|
||||
public async getAttribute(selector: string, attribute: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return Promise.resolve(this.spectron.client.getAttribute(selector, attribute));
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ export class SpectronClient {
|
|||
}
|
||||
|
||||
public async isVisible(selector: string, capture: boolean = true): Promise<any> {
|
||||
await this.execute(capture);
|
||||
await this.screenshot(capture);
|
||||
return this.spectron.client.isVisible(selector);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ export class SpectronClient {
|
|||
return this.spectron.client.getTitle();
|
||||
}
|
||||
|
||||
private async execute(capture: boolean): Promise<any> {
|
||||
private async screenshot(capture: boolean): Promise<any> {
|
||||
if (capture) {
|
||||
try {
|
||||
await this.shot.capture();
|
||||
|
|
Loading…
Reference in a new issue