本文整理匯總了TypeScript中protractor.browser.takeScreenshot方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript browser.takeScreenshot方法的具體用法?TypeScript browser.takeScreenshot怎麽用?TypeScript browser.takeScreenshot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類protractor.browser
的用法示例。
在下文中一共展示了browser.takeScreenshot方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: writeScreenshot
export async function writeScreenshot(filename: string) {
let png = await browser.takeScreenshot();
let stream = fs.createWriteStream(filename);
stream.write(new Buffer(png, 'base64'));
stream.end();
info(`Saved screenshot to: ${filename}`);
}
示例2: After
After(async function(scenario) {
if (scenario.result.status === Status.FAILED) {
// screenShot is a base-64 encoded PNG
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
}
});
示例3: takeScreenShot
export function takeScreenShot(fileName?: string, pathName?: string) {
const pathNameFinal = pathName || './e2e/screenshots';
const fileNameFinal = fileName || Date.now().toString();
browser.takeScreenshot()
.then((png) => {
const file = path.resolve(path.join(pathNameFinal, fileNameFinal + '.png'));
fs.writeFileSync(file, png, { encoding: 'base64' });
});
}
示例4: function
this.specDone = function (result) {
if (result.failedExpectations.length > 0) {
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(`e2e/error-${result.description}.png`);
stream.write(new Buffer(png, 'base64'));
stream.end();
});
}
};
示例5: Buffer
this.After((scenario, done) => {
if (scenario.isFailed()) {
return browser.takeScreenshot().then(function (base64png) {
let decodedImage = new Buffer(base64png, 'base64').toString('binary');
scenario.attach(decodedImage, 'image/png');
}, (err) => {
done(err);
});
} else {
done();
}
});
示例6: takeScreenshot
export async function takeScreenshot(name: string) {
await changeAppleSysFont();
const config = await browser.getProcessedConfig();
const deviceName = config['capabilities'].name;
// gets set when debugging in a single instance
const device = deviceName ? deviceName : 'debug';
const pngData = await browser.takeScreenshot();
const path = join(dir, `${name}_${device}.png`);
writeFile(path, pngData, { encoding: 'base64' }, err => {
// tslint:disable-next-line:no-console
err ? console.error(err) : console.log(`File written: ${path}`);
});
}
示例7: afterEach
/**
* An example 'after' hook that will be run after every scenario.
*/
@after()
private async afterEach(scenario: HookScenarioResult) {
let success = scenario.result.status === Status.PASSED ? 'successfully' : 'unsuccessfully';
console.log(`The scenario '${scenario.pickle.name}' has completed ${success}`);
// Taking a screenshot of the browser if the scenario has failed.
if (scenario.result.status === Status.FAILED) {
let screenshot = await browser.takeScreenshot();
let browserName = (await browser.getCapabilities()).get('browserName');
let filename = browserName + ' FAIL - ' + scenario.pickle.name + '.png';
Utils.writeScreenshot(screenshot, filename)
}
}
示例8:
browser.enterRepl(0, 0);
browser.enterRepl('1');
browser.enterRepl(true);
browser.enterRepl(() => {});
browser.pause(0, 0);
browser.pause('1');
browser.pause(true);
browser.pause(() => {});
browser.actions(0);
browser.actions('1');
browser.actions(true);
browser.actions(() => {});
browser.wait('condition', '1');
browser.wait('condition', true);
browser.wait('condition', () => {});
browser.wait('condition', 100, 0);
browser.wait('condition', 100, true);
browser.wait('condition', 100, () => {});
browser.getCurrentUrl(0);
browser.getCurrentUrl('1');
browser.getCurrentUrl(true);
browser.getCurrentUrl(() => {});
browser.getTitle(0);
browser.getTitle('1');
browser.getTitle(true);
browser.getTitle(() => {});
browser.takeScreenshot(0);
browser.takeScreenshot('1');
browser.takeScreenshot(true);
browser.takeScreenshot(() => {});
示例9: constructor
constructor(id: string) {
this.id = `${currentJasmineSpecName} ${id}`;
browser.takeScreenshot().then(png => this.storeScreenshot(png));
}
示例10: async
let createScreenshot = async(): string => {
let data = await browser.takeScreenshot();
let path = fs.writeFileSync('./e2e/screenshot.png', data, 'base64');
console.log('CREATED SCREENSHOT: ', path);
return path;
}