var casper = require("casper").create ({
logLevel: "error",
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)",
pageSettings: {
loadImages: false, // do not load images
loadPlugins: false // do not load NPAPI plugins (Flash, Silverlight, ...)
}
});
casper.start();
collectTracking();
casper.run();
function collectTracking(){
casper.then(function() {
logIn();
});
}
//LogIn
var password = 'password';
var Css3loginLink = 'div.loggedOff';
var Css3loginForm = 'form[name="loginForm"]';
var Css3loginButton = 'button[class*="ValidateLogin"]';
var Css3loginID = '#txtLoginEmailID';
var Css3loginPwd = '#txtLoginPwd';
function logIn() {
console.log("Beginning Login Function");
casper.thenOpen(urlBasePage , function then() {
if(this.exists(Css3loginLink)) {
this.thenClick(Css3loginLink);
this.then(function() {
this.waitForSelector(Css3loginButton, function then() {
this.then(function() {
this.wait(5000, function() {
this.capture("./CasperError/1LoginFormReady.png");
});
});
this.then(function() {
this.fill(Css3loginForm, {
'/atg/userprofiling/ProfileFormHandler.value.login': email,
'/atg/userprofiling/ProfileFormHandler.value.password': password
});
});
this.then(function() {
this.capture("./CasperError/2LoginFormCompleted.png");
});
this.then(function() {
this.thenClick(Css3loginButton);
});
this.then(function() {
this.wait(5000, function() {
if(this.exists(Css3loginButton)) {
console.log('Login Form Failed');
this.capture("./CasperError/3LoginFormFailed.png");
}
});
});
});
});
}
this.then(function() {
this.exit;
});
});
}