Skip to content

Instantly share code, notes, and snippets.

@miconblog
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miconblog/10c44a1f48d50cb446a1 to your computer and use it in GitHub Desktop.
Save miconblog/10c44a1f48d50cb446a1 to your computer and use it in GitHub Desktop.
Login & Register Event with phantomjs
var page = new WebPage();
var config = require('./config');
var loginsuccess = false;
var imageFormat = {format: 'png', quality: '10'};
var USER = {};
var USER_INDEX = 0;
page.onUrlChanged = function(targetUrl){
if( targetUrl === config.mainUrl ){
console.log("로그인 성공!");
loginsuccess = true;
}
}
page.onLoadFinished = function(status) {
if( loginsuccess ){
page.render("images/" + USER.id + "_step2_after_login.png", imageFormat);
loadLoginEventPage();
loginsuccess = false;
}
};
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg );
};
function loadLoginPage(){
console.log("Load Login Page");
page.settings.userAgent = config.agent;
page.open(config.loginUrl, function(state){
if( state === 'success'){
enterCredential();
}
});
}
function enterCredential(){
page.render("images/" + USER.id + "_step1_before_login.png", imageFormat);
page.evaluate(function(user) {
$('#login_id').val(user.id);
$('#login_pwd').val(user.pwd);
$('.btn_login.xl.btn_right').click();
}, USER);
}
function loadLoginEventPage(){
console.log("이벤트 페이지로 이동!", config.eventUrl);
page.open(config.eventUrl, function(state){
if( state === 'success'){
page.render("images/" + USER.id + "_step3_before_event.png", imageFormat);
sendLoginEvent();
}
});
}
function sendLoginEvent(){
console.log('로그인 이벤트 응모!');
page.evaluate(function () {
$("map area[shape='circle']").click();
});
setTimeout(function(){
page.render("images/" + USER.id + "_step4_after_event.png", imageFormat);
console.log("응모 완료!")
next();
}, 2000);
}
function next(){
USER = config.users[USER_INDEX];
if(USER){
console.log(USER.id, '님 로그인 이벤트 응모 시작!')
loadLoginPage();
USER_INDEX++;
}else{
phantom.exit();
}
}
next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment