I am attempting to run my casperjs script by clicking a Run button in a website. My local set up is PHP 5.5.14 with Apache 2.4 on Windows7 [properly running; tested with php page]; and my question is: how do I properly install casperJS and phantomJS so that its PATH is recognized when I execute the script. I need to know what the path is in Windows to be able to use this: putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");. I have gone over the following possible solutions but none of them mention on how to properly install casperJS and phantomJS for the web server to recognize them: CasperJS passing data back to PHP, Pass parameter from php to casperjs/phantomjs, How to run casperJS script from php API, Using casperjs and PHP to save data, php execution phantom js works but casperjs does not work permission denied
This is my current script for multiple users to log-in to a page, log-out and then return how many successes/failures.
var casper = require('casper').create()
var colorizer = require('colorizer').create('Colorizer');
var userNames = ['username1','username2','username3','username4', 'username5'];
var passWords = ['password1','password2','password3','password4', 'password5'];
var url = 'http://mywebsitenet.com';
var tracker = {Success: [], Fail: []};
function login(username, password) {
casper.then(function () {
this.sendKeys('#log', username);
this.sendKeys('#pwd', password);
this.click('#wpmem_login > form > fieldset > div.button_div > input.buttons');
// console.log(username + " has clicked the Log In button!")
});
casper.waitFor(function check() {
return this.evaluate(function() {
return document.getElementById('wp-admin-bar-logout');
});
}, function then() { // step to execute when check() is ok
this.click('#wp-admin-bar-logout > a');
tracker.Success.push(username);
this.echo(this.fetchText('#wp-admin-bar-my-account > a') + " you logged in.");
this.capture('Success_'+username+'.png');
}, function timeout() { // step to execute if check has failed
tracker.Fail.push(username);
this.echo("Warning: " + username + " could not be logged in.", "WARNING");
this.capture('Fail_'+username+'.png');
});
};
casper.start(); // empty page
casper.viewport(1024, 768);
userNames.forEach(function(username, index){
casper.thenOpen(url); // open the start page
login(username, passWords[index]); // schedule the steps
});
casper.then(function () {
this.echo("Success: " + tracker.Success.length, "INFO");
this.echo("Fail: " + tracker.Fail.length, "WARNING");
this.echo(JSON.stringify(tracker));
});
casper.run(); // begin the execution