I can't figure out how to do the following:
Before running my tests I would like to post (multipart) a file to the server. Our backend creates content profiles for these uploads which can then be accessed through the UI. It's this content profile I need to run tests on.
I am aware of the .fill() functionality but this does not apply as I do not want to do file uploads through the UI. Is there any way this can be achieved via CasperJS or javascript or can anyone point me to documentation that might help me?
As far as I have read the documentations of both casperjs and phantomjs, direct file submissions are not allowed. You may use curl like below:
curl http://some.testserver.com/post.php \
-F file_input=@/path/to/my/file.txt \
-F "text_field=Some Text Here" \
-F some_number=1234
You can however open a POST request on casperjs:
casper.start();
casper.open('http://some.testserver.com/post.php', {
method: 'post',
data: {
'title': 'Plop',
'body': 'Wow.'
},
headers: {
'Content-type': 'multipart/form-data'
}
});
casper.then(function() {
this.echo('POSTED it.');
});
casper.run();
Here is the relevant documentation:
http://docs.casperjs.org/en/latest/modules/casper.html#open
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With