webdriverio-boneyard / v4

Deprecated code base for all WebdriverIO releases up until v4.x
MIT License
8 stars 21 forks source link

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

Open christian-bromann opened 5 years ago

christian-bromann commented 5 years ago

From @rsshilli on March 1, 2019 21:25

Environment:

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 commented 5 years ago

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

christian-bromann commented 5 years ago

see https://github.com/webdriverio/webdriverio/pull/3632

kashinross commented 5 years ago

@christian-bromann Awesome, thanks!