當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Page.evaluate方法代碼示例

本文整理匯總了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
    }
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:45,代碼來源:bridge.ts

示例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}`);
      }
    });
開發者ID:vega,項目名稱:vega-lite,代碼行數:18,代碼來源:discrete.test.ts

示例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();
 });
開發者ID:vega,項目名稱:vega-lite,代碼行數:19,代碼來源:interval.test.ts

示例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`);
  });
開發者ID:vega,項目名稱:vega-lite,代碼行數:16,代碼來源:toggle.test.ts


注:本文中的puppeteer.Page.evaluate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。