Last active
August 29, 2015 14:03
-
-
Save GuoJing/fdf01c27b32c1087425b to your computer and use it in GitHub Desktop.
casper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var c = require('framework.js'); | |
var _step1_url = c.url + '/mine/info/1' | |
var _step2_url = c.url + '/mine/info/2' | |
var _step3_url = c.url + '/mine/info/3' | |
var _step4_url = c.url + '/mine/info/4' | |
var _step5_url = c.url + '/mine/info/5' | |
var check_loaded = function(){ | |
casper.waitForResource(/form_helper\.js$/, function(){ | |
}); | |
casper.then(function(){ | |
this.wait(5000, function(){ | |
this.echo('5000ms waited'); | |
}) | |
}); | |
} | |
casper.test.begin("some title", function(test) { | |
c.login(test, '[email protected]', 'testtest'); | |
casper.on('remote.alert', function(msg) { | |
this.log('Alert: ' + msg, 'warning'); | |
}); | |
casper.on('remote.message', function(msg) { | |
this.log('Msg: ' + msg, 'warning'); | |
}); | |
casper.on('step.added', function(step) { | |
this.log('Step: ' + step, 'warning'); | |
}); | |
casper.thenOpen(_step1_url); | |
casper.then(function(){ | |
var _html = this.getHTML(); | |
}); | |
check_loaded(); | |
casper.then(function(){ | |
this.fill("form", { | |
gender : "female", | |
age : 30, | |
career : "1", | |
marriage : "1", | |
phone : "18618193877", | |
qq : "455383101", | |
}, false); | |
this.click('a.form-submit'); | |
}); | |
casper.waitFor(function(){ | |
return this.getCurrentUrl() === _step2_url | |
}); | |
casper.then(function(){ | |
test.assert(this.getCurrentUrl() === _step2_url, "step2"); | |
}); | |
check_loaded(); | |
casper.then(function(){ | |
this.fill("form", { | |
income_month_salary : 20000, | |
income_month_extra : 101, | |
income_year_bonus : 102, | |
income_year_extra : 103, | |
expend_month_ent : 1000, | |
expend_month_trans : 500, | |
expend_month_shopping : 600, | |
expend_month_house : 700, | |
expend_month_extra : 800, | |
expend_year_extra : 900, | |
}, false); | |
this.click('a.form-submit'); | |
}); | |
casper.waitFor(function(){ | |
return this.getCurrentUrl() === _step3_url; | |
}); | |
casper.then(function(){ | |
var _html = this.getHTML(); | |
test.assert(this.getCurrentUrl() === _step3_url, "step3"); | |
}); | |
check_loaded(); | |
casper.then(function(){ | |
this.fill("form", { | |
mine_society_insure: "2", | |
}, false); | |
this.click('a.form-submit'); | |
}); | |
casper.waitFor(function(){ | |
return this.getCurrentUrl() === _step4_url; | |
}); | |
casper.then(function(){ | |
var _html = this.getHTML(); | |
test.assert(this.getCurrentUrl() === _step4_url, "step4"); | |
}); | |
check_loaded(); | |
casper.then(function(){ | |
this.fill("form", { | |
deposit_current : 10000, | |
deposit_fixed : 10001, | |
funds_money : 2000, | |
funds_hybrid : 2001, | |
funds_bond : 2002, | |
funds_stock : 2003, | |
funds_other : 2004, | |
invest_bank : 3001, | |
invest_stock : 3002, | |
invest_national_debt : 3003, | |
invest_p2p : 3004, | |
consumer_loans : 5001, | |
}, false); | |
this.click('a.form-submit'); | |
}); | |
casper.waitFor(function(){ | |
return this.getCurrentUrl() === _step5_url; | |
}); | |
casper.then(function(){ | |
var _html = this.getHTML(); | |
test.assert(this.getCurrentUrl() === _step5_url, "step5"); | |
}); | |
check_loaded(); | |
casper.then(function(){ | |
var fillup = this.evaluate(function() { | |
$(".target").val("1").trigger("change"); | |
$(".target-money").val(10000); | |
$(".target-year").val(5); | |
return 'filled up'; | |
}); | |
this.fill("form", { | |
invest_exp : "1", | |
invest_concern : "2", | |
invest_risk_rage : "3", | |
invest_handle : "2", | |
}, false); | |
this.click('a.form-submit'); | |
}) | |
casper.waitFor(function(){ | |
return this.getCurrentUrl() === c.mine_url; | |
}); | |
casper.then(function(){ | |
test.assert(this.getCurrentUrl() === c.mine_url, "end steps"); | |
}); | |
casper.run(function(){ | |
test.done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment