R
R
Roman2015-02-26 17:21:57
Angular
Roman, 2015-02-26 17:21:57

How to write an integration test (protractor) for multi-uploading files in Chrome?

Hello everyone
I am solving the problem of testing a multi-file upload form in a browser
For multi-upload, the angular-file-upload module is used ( https://github.com/nervgh/angular-file-upload )
The form needs to be tested in two browsers in IE 11 version and Chrome
Yes the condition that during multi-upload the number of simultaneously downloaded files should not be more than 5
Ok, for testing I use Protractor (e2e test framework based on WebDriverJS)
Here is the test code itself

it('A user attaches fileы with correct existantion', function () {
        var validFile = '../test/filesToUpload/testxlsx.xlsx',
            validFile2 = '../test/filesToUpload/testxls.xls',
        var absolutePath = path.resolve(__dirname, validFile);
        var absolutePath2 = path.resolve(__dirname, validFile2);
        $('#ifile').sendKeys('"' +absolutePath2 + '" "' +absolutePath +'"');
        var absolutePath = path.resolve(__dirname, invalidFile);
        var errorMessageElement = $('.contactForm__errorMessage');
        expect(errorMessageElement.getText()).toEqual('');
    });

Let me explain a little
In Chrome (and in IE) when selecting multiple files for multi-upload, file names are enclosed in quotes and are written with a space.
I run the test - in IE everything is ok (yes, in IE it's not strange), but in Chrome the test fails with an error:
I.e. chrome doesn't understand my two files quoted and separated by space.
UnknownError: unknown error: path is not absolute: "E:\MyProjects\tns\test\filesToUpload\testxls.xls"
"E:\MyProjects\tns\test\filesToUpload\testxlsx.xlsx"

Tried with both relative and absolute paths - the picture is the same, everything is OK in IE, the test fails in chrome
Who came across, tell me, pliz!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2015-02-26
@sHinE

The option is purely on the ball, but did you try to slash in the other direction or escape in the paths?

R
Roman, 2015-02-27
@uaKorona

In the wilds of the Internet, I found a solution
for Chrome files should be separated '\n'
But unlike IE, file names should not be wrapped in quotes

if (browser.browserName === 'chrome') {
            resultPath = absolutePaths.join('\n');
        }
      
  if (browser.browserName === 'internet explorer') {
            var newAbsolutePaths = [];
            absolutePaths.forEach(function (path) {
                newAbsolutePaths.push('"' + path + '"');
            });
            resultPath = newAbsolutePaths.join(' ');
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question