PhantomJS2.0+ CasperJS1.0.4 mac

修改vi bootstrap.js


if (!phantom) {
    console.error('CasperJS needs to be executed in a PhantomJS environment http://phantomjs.org/');
}
else {
if (phantom.version.major === 2) {
//setting other phantom.args if using phantomjs 2.x
var system = require('system');
var argsdeprecated = system.args;
argsdeprecated.shift();
phantom.args = argsdeprecated;
}
}

./casperjs test.js






var casper = require('casper').create({ 
 verbose: true, 
 logLevel: 'debug',
 pageSettings: {
 loadImages: false, 
 loadPlugins: true, 
 userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0'
}
});
//phantom.outputEncoding="gbk";
casper.options.viewportSize = {width: 1680, height: 924};
casper.start('http://bulo.hujiang.com/app/login?source=nbulo&returnurl=/home/');
casper.waitForSelector("form#myform input[name='txtUsername']",
 function success() {
 this.test.assertExists("form input[name='txtUsername']");
this.fill("form",{
'txtUsername':'shixiaobao17',
 'txtPassword':'×××××your password*****'
},false);
this.click("input#btnLogin");
},
 function fail() {
 this.test.assertExists("form input[name='txtUsername']");
});

casper.waitFor(function check() {
return this.getCurrentUrl().indexOf("bulo.hujiang.com/home")>-1;
}, function then() {
console.log("登录成功!!!!!!!!!!!!");
}).then(function(){
console.log("执行登录后的其它操作!!!!!!!!!!!!");
if(this.exists("#btn_card_do")){
this.click("#btn_card_do");
this.waitForSelector("#my_hb_btn",function success(){
console.log("打卡成功!");
 },function fail(){
console.log("打卡失败!");
});
}else{
console.log("今天已经打过卡啦!");
}

});
casper.run(function() {this.test.renderResults(true);});

你可能感兴趣的:(自动化测试)