Skip to content

Commit

Permalink
feat: 增加世界邦provider
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Oct 28, 2017
1 parent b6f2bc7 commit 16b6efd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ class App extends EventEmitter {
await pTimeout(entity.resolve(this), 1000 * 60)
.then(() => {
utils.log(chalk.green('[Success]:'), entity.name);
return Promise.resolve();
})
.catch(err => {
// 等待超时,忽略掉
utils.log(chalk.red('[Fail]:'), entity.name);
// 如果是等待超时
// 则很有可能是验证是否发送成功
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) {
Expand Down
23 changes: 23 additions & 0 deletions app/providers/世界邦.js
Original file line number Diff line number Diff line change
@@ -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 });
}
};
1 change: 1 addition & 0 deletions example/once.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ app
console.info(`进入到 ${ctx.currentPage}`);
})
.on('error', err => {
console.error(`something go wrong`);
console.error(err);
})
// bootstrap
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 16b6efd

Please sign in to comment.