Exploring CasperJS has been a great experience for me. Despite my enjoyment, I've encountered an issue with casper.capture() that has me stumped. I've set it up to capture screenshots whenever a test fails and placed it in a separate setup module as shown below:
function captureFailure(filename){
casper.test.on("fail", function(failure){
casper.viewport(1280, 1024);
casper.capture("failedScreenshots/Failure-"+filename+".jpg", {
top: 0,
left: 0,
width: 1280,
height: 1024
});
});
}
exports.captureFailure = captureFailure;
Then, in my tests, I incorporate it like this:
. . .
// execute setup
setup.login();
// perform test
casper.test.begin("Complete new social campaign flow with image as a signed in user.", 16, function suite(test) {
// initialize captureFailure
setup.captureFailure("SocialFlowImage");
casper.start(data.baseURL+'/campaigns/', function(){
console.log("Campaign page loaded");
this.click(campaignCreate);
casper.waitForSelector(socialCampaignCreateModal, function(){
test.assertExists(socialCampaignCreateModal, 'Modal pops up');
test.assertTextExists('Deal', 'Deal button exists');
test.assertTextExists('Marketing Email', 'Marketing Email button exists');
test.assertTextExists('Facebook', 'Facebook button exists');
});
});
. . .
Initially, everything was functioning properly. However, when testing multiple failures simultaneously, the screenshots were being overwritten sequentially. The sequence looked something like this:
test 1 -> test 1 failure -> Capture screenshot 1 -> test 2 -> test 2 failure -> Capture screenshot 2 and subsequently overwrite screenshot 1
This resulted in having duplicate screenshots with different names.
Any suggestions on how to resolve this issue?