Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Browser.chooseFile() sets the file to being modified in the future #22

Open
christian-bromann opened this issue Mar 4, 2019 · 3 comments

Comments

@christian-bromann
Copy link
Contributor

From @rsshilli on March 1, 2019 21:25

Environment:

  • WebdriverIO version: 4.4.0
  • Mode: Standalone mode (packaged with Chimp)
  • Node.js version: 8.10.0
  • NPM version: 6.0.1
  • Browser name and version: Chrome 72.0.3626.119
  • Platform name and version: Windows 10
  • Additional wdio packages used (if applicable):

Config of WebdriverIO
I'm using WebdriverIO through Chimp. My webdriverio configuration is:

  webdriverio: {
    logLevel: "verbose",
    logOutput: "build/test/report",
    deprecationWarnings: false,
    coloredLogs: !isBuildSystem,
    waitforTimeout: (isBuildSystem ? 120 : 30)*1000,
  },

Describe the bug
When I use browser.chooseFile(), Chrome accepts the file properly and uploads it. Using the File API (https://www.w3.org/TR/FileAPI/) the code on my webpage is getting the file name, size, and the last modified date to show it in the UI after it's been uploaded.

When I upload a file that was last modified yesterday, the file is uploaded as having been last modified 5 hours from now! Woah, it's like a glimpse into the future! Except I'm pretty sure it's because I'm in UTC-5.

After looking into the Chrome logs, I see that my original file is not the one sent to Chrome, but instead the file is being copied to a new location and being sent from there:

[15:49:40]  COMMAND	POST 	 "/wd/hub/session/fa5b1d54954b4ee5f61be6b445c83c9d/file"
[15:49:40]  DATA		{"file":"[base64] 38744 bytes"}
[15:49:40]  RESULT		"C:\\Users\\ryans\\AppData\\Local\\Temp\\scoped_dir30340_24649\\upload30340_15490\\SampleUpload2.pdf"

That's weird. When I look at that file, it's also in the future! Note above that I sent the file at 3:49pm

C:\> dir C:\Users\ryans\AppData\Local\Temp\scoped_dir30340_24649\upload30340_15490\SampleUpload2.pdf
 Volume in drive C is Windows
 Volume Serial Number is 407E-A66F

 Directory of C:\Users\ryans\AppData\Local\Temp\scoped_dir30340_24649\upload30340_15490

03/01/2019  08:49 PM            29,887 SampleUpload2.pdf
               1 File(s)         29,887 bytes
               0 Dir(s)  47,966,064,640 bytes free

I don't know how this magic is happening. Is it possible that the file doesn't need to be copied? Or maybe that the last modified date should be kept, as opposed to being set to the current time in UTC?

To Reproduce

Here's my code to use Webdriver.io to upload the file:

    let filePath = path.join(__dirname, "..", "files", fileName);
    browser.chooseFile("#uploadDocumentButton", filePath);

Here's a sample of the code in the browser that gets the date:

  let input = $("#" + event.target.id)[0];

  if (input.files) {
    let file = input.files[0];
    fileData.fileName = file.name;
    fileData.size = file.size;
    fileData.lastModified = file.lastModified;

Expected behavior
I would expect the file's original last modified date to be what I see in my JavaScript running in Chrome.

Log
Chrome log is included in the bug description above.

Additional context
My code in the browser works fine when I choose the file manually.

Copied from original issue: webdriverio/webdriverio#3665

@kashinross
Copy link

@christian-bromann is there an equivalent to chooseFile in WDIO5?

@christian-bromann
Copy link
Contributor Author

christian-bromann commented Mar 19, 2019

see webdriverio/webdriverio#3632

@kashinross
Copy link

@christian-bromann Awesome, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants