I'm trying to automate download CSV file from APEX application.
var casper = require('casper').create({verbose: true, logLevel: "debug", viewportSize: { width: 1600, height: 400 } });
var url = "https://example.com"
casper.start(url);
casper.then(function () {
this.fill('#wwvFlowForm', {'P101_USERNAME': 'user', 'P101_PASSWORD': 'password'}, false);
});
casper.then(function () {
this.click('#P101_LOGIN');
}).wait(5000).then(function () {
this.echo('downloading file');
this.download('https://example/apex/f?p=1002:173:10072525691961:CSV','report.csv')
});
casper.run();
I am able to login, but when i try to download file i am getting login page html. I have tried using getBase64 method with same result. Does casper.download using different session? Screenshots before and after download shows that i am logged in.
Issue was that this apex app is using instance_id in url so working code is:
var casper = require('casper').create({verbose: true, logLevel: "debug",
viewportSize: { width: 1600, height: 400 } });
var url = "https://example.com"
casper.start(url);
casper.then(function () {
this.fill('#wwvFlowForm', {'P101_USERNAME': 'user', 'P101_PASSWORD': 'password'}, false);
});
casper.then(function () {
this.click('#P101_LOGIN');
}).wait(5000).then(function () {
this.echo('downloading file');
var instance_id = this.getCurrentUrl().split(':')[3];
var download_url = url + '/apex/f?p=1002:173:' + instance_id;
this.download('download_url' + ':CSV','report.csv')
});
casper.run();