Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Possbility to test file upload initiated by javascript #546

Closed
miks opened this issue Jul 20, 2013 · 7 comments
Closed

Possbility to test file upload initiated by javascript #546

miks opened this issue Jul 20, 2013 · 7 comments

Comments

@miks
Copy link
Contributor

miks commented Jul 20, 2013

I have page to test where actual file upload input is hidden and upload itself is triggered with click event from simple button.
With capybara 2.1.0 and capybara webkit 1.0.0 I have no clue how to test this kind of interface. When test trigger click on UI button within capybara-webkit and save screenshot there is no upload dialog present (unlike in real browser).
Also "attach_file" method is failing as file upload input is hidden.

@mhoran
Copy link
Collaborator

mhoran commented Aug 14, 2013

This is an unfortunate side effect of the changes required to make capybara-webkit compatible with Qt 5.0. As of Qt 5, opening a file dialog must be initiated by a user action, which requires a "native click" event. There's an upstream QtWebKit bug which has gone unanswered for over a year.

We've been unable to come up with an alternative solution to the click issue, however it has also caused other issues for users who have applied certain styling (inline-block) to elements, which WebKit is unable to click. There's also a Capybara 2.1 feature, #hover, which requires native mouse event support.

@jferris
Copy link
Contributor

jferris commented Nov 9, 2013

@miks are you doing this using JavaScript so that you can style the upload button? Can you try a technique that doesn't hide the actual upload, like this one? http://www.quirksmode.org/dom/inputfile.html

@miks
Copy link
Contributor Author

miks commented Dec 14, 2013

It's not related to style. We have upload functionality like this:

  1. there is simple button with name "import file"
  2. user click to button which trigger file input click event, which therefore open file upload dialog
  3. when file input is changed, form is submited with FormData through ajax request.

This approach allow to minimize UI for fast file upload.

@acrogenesis
Copy link

@miks did you solve this? I'm having trouble with this

@miks
Copy link
Contributor Author

miks commented Jan 31, 2015

@acrogenesis I just made form and regular file input visible for tests like (here: https://github.com/cubesystems/releaf/blob/master/releaf-i18n_database/spec/features/translations_spec.rb#L78)

@acrogenesis
Copy link

Thanks that worked 👍

@calleluks
Copy link

I'm closing this issue since it seems to be resolved.

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

5 participants