From 16b6efdbcbf398d6548c68ec9e1dd93f0fb32cbd Mon Sep 17 00:00:00 2001 From: axetroy Date: Sat, 28 Oct 2017 11:20:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=96=E7=95=8C?= =?UTF-8?q?=E9=82=A6provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.js | 4 +++- .../\344\270\226\347\225\214\351\202\246.js" | 23 +++++++++++++++++++ example/once.js | 1 + index.js | 3 ++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 "app/providers/\344\270\226\347\225\214\351\202\246.js" diff --git a/app/app.js b/app/app.js index c5d7bec..d9284bd 100644 --- a/app/app.js +++ b/app/app.js @@ -107,6 +107,7 @@ class App extends EventEmitter { await pTimeout(entity.resolve(this), 1000 * 60) .then(() => { utils.log(chalk.green('[Success]:'), entity.name); + return Promise.resolve(); }) .catch(err => { // 等待超时,忽略掉 @@ -114,8 +115,9 @@ class App extends EventEmitter { // 如果是等待超时 // 则很有可能是验证是否发送成功 if (err instanceof Error && err.message.indexOf('waiting failed')) { + return Promise.resolve(); } else if (err) { - this.emit(EVENT_ON_ERROR, err); + return Promise.reject(err); } }); } catch (err) { diff --git "a/app/providers/\344\270\226\347\225\214\351\202\246.js" "b/app/providers/\344\270\226\347\225\214\351\202\246.js" new file mode 100644 index 0000000..3a4b76c --- /dev/null +++ "b/app/providers/\344\270\226\347\225\214\351\202\246.js" @@ -0,0 +1,23 @@ +const Provider = require('../provider'); +const utils = require('../utils'); + +module.exports = class extends Provider { + constructor() { + super(); + this.url = `http://www.shijiebang.com/reg/`; + this.alone = true; + } + async resolve(ctx) { + const options = ctx.options; + const page = ctx.page; + + await page.waitForSelector('input[type="mobile"]', { timeout: 1000 * 3 }); + await page.type('input[type="mobile"]', options.phone, { delay: 50 }); + + await utils.sleep(500); + + // 点击发送验证码 + await page.click('button.btn.sp2'); + await page.waitForSelector('button.btn.sp2.disabled', { timeout: 1000 * 3 }); + } +}; diff --git a/example/once.js b/example/once.js index 5a39887..9f599bb 100644 --- a/example/once.js +++ b/example/once.js @@ -10,6 +10,7 @@ app console.info(`进入到 ${ctx.currentPage}`); }) .on('error', err => { + console.error(`something go wrong`); console.error(err); }) // bootstrap diff --git a/index.js b/index.js index 9566c50..a56ed2b 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,8 @@ process.on('exit', () => { }); process.on('uncaughtException', err => { - console.error('Error caught in uncaughtException event:', err); + console.error('Error caught in uncaughtException event:'); + console.error(err); }); process.on('unhandledRejection', (reason, p) => {