本文整理汇总了TypeScript中puppeteer.Page.evaluate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Page.evaluate方法的具体用法?TypeScript Page.evaluate怎么用?TypeScript Page.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类puppeteer.Page
的用法示例。
在下文中一共展示了Page.evaluate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
public async inject(page: Page): Promise<void> {
log.verbose('PuppetPuppeteerBridge', 'inject()')
const WECHATY_BRO_JS_FILE = path.join(
__dirname,
'wechaty-bro.js',
)
try {
const sourceCode = fs.readFileSync(WECHATY_BRO_JS_FILE)
.toString()
let retObj = await page.evaluate(sourceCode) as any as InjectResult
if (retObj && /^(2|3)/.test(retObj.code.toString())) {
// HTTP Code 2XX & 3XX
log.silly('PuppetPuppeteerBridge', 'inject() eval(Wechaty) return code[%d] message[%s]',
retObj.code, retObj.message)
} else { // HTTP Code 4XX & 5XX
throw new Error('execute injectio error: ' + retObj.code + ', ' + retObj.message)
}
retObj = await this.proxyWechaty('init')
if (retObj && /^(2|3)/.test(retObj.code.toString())) {
// HTTP Code 2XX & 3XX
log.silly('PuppetPuppeteerBridge', 'inject() Wechaty.init() return code[%d] message[%s]',
retObj.code, retObj.message)
} else { // HTTP Code 4XX & 5XX
throw new Error('execute proxyWechaty(init) error: ' + retObj.code + ', ' + retObj.message)
}
const SUCCESS_CIPHER = 'ding() OK!'
const future = new Promise(resolve => this.once('dong', resolve))
this.ding(SUCCESS_CIPHER)
const r = await future
if (r !== SUCCESS_CIPHER) {
throw new Error('fail to get right return from call ding()')
}
log.silly('PuppetPuppeteerBridge', 'inject() ding success')
} catch (e) {
log.verbose('PuppetPuppeteerBridge', 'inject() exception: %s. stack: %s', e.message, e.stack)
throw e
}
}
示例2: it
it('should support selecting bins', async () => {
const encodings = ['x', 'color', 'y'];
const fields = ['a', 'c', 'b'];
const types = ['R-RE', 'E', 'R-RE'];
const values = [[[1, 2], 0, [40, 50]], [[8, 9], 1, [10, 20]]];
for (let i = 0; i < hits.bins.length; i++) {
await embed(spec('unit', i, {type, encodings}, {x: {bin: true}, y: {bin: true}}));
const store = await page.evaluate(pt('bins', i));
expect(store).toHaveLength(1);
expect(store[0].fields).toHaveLength(fields.length);
expect(store[0].values).toHaveLength(fields.length);
expect(store[0].fields.map((f: any) => f.field)).toEqual(fields);
expect(store[0].fields.map((f: any) => f.type)).toEqual(types);
expect(store[0].values).toEqual(values[i]);
await testRender(`bins_${i}`);
}
});
示例3: it
it('should add extents to the store', async done => {
for (let i = 0; i < hits.drag.length; i++) {
await embed(spec('unit', i, {type}));
const store = await page.evaluate(brush('drag', i));
expect(store).toHaveLength(1);
expect(store[0].fields).toHaveLength(2);
expect(store[0].values).toHaveLength(2);
expect(store[0].fields[0].channel).toBe('x');
expect(store[0].fields[0].field).toBe('a');
expect(store[0].fields[0].type).toBe('R');
expect(store[0].fields[1].channel).toBe('y');
expect(store[0].fields[1].field).toBe('b');
expect(store[0].fields[1].type).toBe('R');
expect(store[0].values[0]).toHaveLength(2);
expect(store[0].values[1]).toHaveLength(2);
await testRender(`drag_${i}`);
}
done();
});
示例4: it
it('should clear out the store w/o shiftKey', async () => {
await embed(spec('unit', 1, {type}));
await page.evaluate(toggle('qq', 0, false));
await page.evaluate(toggle('qq', 1, true));
await page.evaluate(toggle('qq', 2, true));
await page.evaluate(toggle('qq', 3, true));
await testRender(`clear_0`);
let store = await page.evaluate(toggle('qq_clear', 0, true));
expect(store).toHaveLength(4);
await testRender(`clear_1`);
store = await page.evaluate(toggle('qq_clear', 1, false));
expect(store).toHaveLength(0);
await testRender(`clear_2`);
});