test script:
==============================================
/*
*
* bn_term4_campus.js: test to generate the term page for the bn input using the campus
*
* casper.js bn_term3_campus.js --url1="foo" --url2="foo1"
*
*
*/
var casper = require('casper').create({
verbose: true,
logLevel: "debug",
waitTimeout: 100000, // new maximum waitTimeout
pageSettings:
{
userAgent: 'Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0'
}
});
phantom.timeout=100000;
phantom.stepTimeout=100000;
var x = require('casper').selectXPath;
phantom.cookiesEnabled = true;
var url1 = casper.cli.get("url1");
var campusVal = casper.cli.get("campusVal");
casper.onResourceRequested = function(requestData, request) {
if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData.headers['Content-Type'] == 'text/css') {
console.log('The url of the request is matching. Aborting: ' + requestData['url']);
request.abort();
}
};
casper.start().then(function() {
this.open(url1, {
method : 'get',
headers : {
'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0'
}
});
});
casper.waitForSelector(x('//a[contains(@title,"Find Textbooks")]'), function() {
//this.echo("here 111...........");
this.click('a[title="Find Textbooks"]');
});
casper.waitForSelector(x('//li[@data-optionvalue="'+campusVal+'"]'), function() {
//this.echo("here...........");
//this.click(x('//li[@data-optionvalue="'+campusVal+'"]'));
this.click('li[data-optionvalue="'+campusVal+'"]');
});
//--should only fire after the campusVal sel..
casper.waitForSelector(x('//li[contains(@class,"termOption")]'), function() {
//this.echo("term... ");
this.echo(this.page.content).exit();
});
casper.run(function () {
// echo results in some pretty fashion
// this.echo(this.debugPage()).exit();
// fs.write(cookie_file, JSON.stringify(phantom.cookies), 644);
// this.echo("finish").exit();
// this.echo(this.page.content).exit();
});
======================================================