Search code examples
ruby-on-railstestingcapybaraintegration-testingcapybara-webkit

How could i test that `chose file` dialog opens(Rails, Capybara)


I must make sure that when i click the button on page, chose file dialog window opens. Do you have any idea about implementing this? I use RoR with Capybara.


Solution

  • Short answer: You can't

    Longer answer: The file selection box is a system modal, which basically freezes everything until a file is selected. Because of this (and for security reasons) drivers handle attaching files to file inputs differently than most fields. It isn't done by sending keystrokes to fields on the page, but rather by shortcutting the file modal from appearing and adding the file behind the scenes. Because of that you really can't write a test that detects the presence of the choose file window.