Download and use file with Protractor e2e test

2020-07-25 10:50发布

问题:

How do I write a test that download a file, and post it in a form.

it "should support download and upload a file", ->
    upload = element(By.id 'UploadInput');
    upload.sendKeys 'C:\\path\\to\\file\\file.txt'

Currently the upload works, but how do I download a file before and get it's path?

回答1:

Solved it by adding the file to project and got the absolute path like this:

it "should support download and upload a file", ->
    upload = element(By.id 'UploadInput');
    upload.sendKeys path.resolve(__dirname, '../../assets/file.txt')