Commit 6eb30652 authored by Jérome Perrin's avatar Jérome Perrin

ui_test_core: allow choosing the MIME type in setFile

parent 1cbe6e56
...@@ -57,17 +57,19 @@ function wrapPromise(promise) { ...@@ -57,17 +57,19 @@ function wrapPromise(promise) {
* <tr> * <tr>
* <td>setFile</td> * <td>setFile</td>
* <td>field_my_file</td> * <td>field_my_file</td>
* <td>/data.jpg myfilename.jpg</td> * <td>/data.jpg myfilename.jpg image/jpg</td>
* </tr> * </tr>
* *
* @param {string} locator the selenium locator * @param {string} locator the selenium locator
* @param {string} url_and_filename the URL and filename, separated by space * @param {string} url_filename_mimetype the URL, filename and optionally mime type,
* separated by spaces
* @returns {() => boolean} * @returns {() => boolean}
*/ */
Selenium.prototype.doSetFile = function(locator, url_and_filename) { Selenium.prototype.doSetFile = function(locator, url_filename_mimetype) {
var tmpArray = url_and_filename.split(' ', 2); var tmpArray = url_filename_mimetype.split(' ', 3);
var url = tmpArray[0]; var url = tmpArray[0];
var fileName = tmpArray[1]; var fileName = tmpArray[1];
var mimeType = tmpArray[2] || 'application/octet-stream';
if (!fileName) { if (!fileName) {
throw new Error('file name must not be empty.'); throw new Error('file name must not be empty.');
...@@ -87,7 +89,7 @@ Selenium.prototype.doSetFile = function(locator, url_and_filename) { ...@@ -87,7 +89,7 @@ Selenium.prototype.doSetFile = function(locator, url_and_filename) {
new ClipboardEvent('').clipboardData || new ClipboardEvent('').clipboardData ||
/* specs compliant (as of March 2018 only Chrome) */ /* specs compliant (as of March 2018 only Chrome) */
new DataTransfer(); new DataTransfer();
dT.items.add(new File([blob], fileName)); dT.items.add(new File([blob], fileName, {type: mimeType}));
fileField.files = dT.files; fileField.files = dT.files;
})); }));
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment