Commit 55b648e8 55b648e883e27b4e72e9b3b54b1835c3f614f8de by Nicolas Perriault

fixed file upload paths in tests

1 parent 189b18fc
......@@ -731,8 +731,11 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
} else {
(function _each(self) {
fillResults.files.forEach(function _forEach(file) {
if (!file || !file.path) {
return;
}
if (!fs.exists(file.path)) {
throw new CasperError('Cannot upload unexistent file: ' + file.path);
throw new CasperError('Cannot upload nonexistent file: ' + file.path);
}
var fileFieldSelector = [selector, 'input[name="' + file.name + '"]'].join(' ');
self.page.uploadFile(fileFieldSelector, file.path);
......
/*global casper __utils__*/
/*jshint strict:false*/
var fs = require('fs');
casper.test.begin('fill() tests', 15, function(test) {
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
......@@ -101,6 +103,8 @@ casper.test.begin('field array', 1, function(test) {
});
casper.test.begin('getFormValues() tests', 2, function(test) {
var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
email: 'chuck@norris.com',
......@@ -109,7 +113,7 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
check: true,
choice: 'no',
topic: 'bar',
file: phantom.casperPath + '/README.md',
file: fpath,
'checklist[]': ['1', '3']
});
});
......@@ -120,7 +124,7 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
"choice": "no",
"content": "Am watching thou",
"email": "chuck@norris.com",
"file": "C:\\fakepath\\README.md",
"file": fpath,
"password": "chuck",
"submit": "submit",
"topic": "bar"
......@@ -134,7 +138,7 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
check: true,
choice: 'yes',
topic: 'bar',
file: phantom.casperPath + '/README.md',
file: fpath,
'checklist[]': ['1', '3']
});
});
......@@ -145,7 +149,7 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
"choice": "yes",
"content": "Am watching thou",
"email": "chuck@norris.com",
"file": "C:\\fakepath\\README.md",
"file": fpath,
"password": "chuck",
"submit": "submit",
"topic": "bar"
......
......@@ -67,7 +67,7 @@ casper.test.begin('Common assertions tests', 43, function(test) {
});
});
casper.test.begin('filled inputs', 7, function(test) {
casper.test.begin('Tester.assertField(): filled inputs', 7, function(test) {
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
'email': '',
......@@ -90,8 +90,8 @@ casper.test.begin('filled inputs', 7, function(test) {
});
});
casper.test.begin('unfilled inputs', 7, function(test) {
var fpath = phantom.libraryPath + '/README.md';
casper.test.begin('Tester.assertField(): unfilled inputs', 7, function(test) {
var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
'email': 'chuck@norris.com',
......@@ -107,7 +107,7 @@ casper.test.begin('unfilled inputs', 7, function(test) {
test.assertField('check', true, 'Tester.assertField() works as expected with checkboxes');
test.assertField('choice', 'no', 'Tester.assertField() works as expected with radios');
test.assertField('topic', 'bar', 'Tester.assertField() works as expected with selects');
test.assertField('file', 'C:\\fakepath\\README.md', 'Tester.assertField() works as expected with file inputs');
test.assertField('file', fpath, 'Tester.assertField() works as expected with file inputs');
test.assertField('checklist[]', ['1', '3'], 'Tester.assertField() works as expected with check lists');
}).run(function() {
test.done();
......