varCasper = require (' Casper ')). Create ({viewportsize:{width:1920, Height:1080 }});varURL1 = ' http://jifen.yuyid.com ';varUsers = [{' username ': ' 150****656 ', ' Password ': ' xxxxxx '},{username: ' username ', password: ' xxxxx '}];casper.start ();varAutosingin =function(value,key) {//Open HomeCasper.thenopen (URL1,function(){ This. Captureselector (' jifen.png ', ' HTML '); This. Wait (1000);//The This.wait method cannot block the execution of the code below the current callback function, only the next code to execute, such as the following Casper.then This. Click (' Div.go-login '); }) //populate the form and sign inCasper.then (function(){ //wait for 1s to execute this callback This. Captureselector (' alert.jpg ', ' HTML '); This. Fill ("Form#login_form", Value,false) This. Captureselector (' filled.jpg ', ' HTML '); This. Click (' a.login-btn '); This. Wait (3000) }) //Click Sign in to open the windowCasper.then (function(){ This. Captureselector (' logined.jpg ', ' HTML '); This. Click (' #sign-btn '); This. Wait (1000); }) //Perform sign -inCasper.then (function(){ This. Captureselector (' click-sigin.png ', ' HTML '); This. Click ('. Sign-btn-a '); This. Wait (1000); }) //sign -in successCasper.then (function(){ This. Capture (' sigin-success-' +key+ '. png '); This. Click ('. User>a ')})}users.foreach (function(Value,key) {Autosingin (Value,key)}) Casper.run ();
Login with Casperjs to support multiple account logins