Reputation: 2095
I'm using a test framework with Ruby, Capybara and SitePrism mainly and up until now I was using the 'attach_file(input_element, File.path)' method successfully.
I've now moved to a different project and they've got this page where there's an 'Upload button' but there's no 'input' element whatsoever in the page on first load (checking the source code, there's not hidden element either, ie, 'input' doesn't appear in the page at all). What's happening then it's that when an user clicks on the 'Upload' button, a windows pop-out appears where they can select their file and when they select that one, there seems to be some javascript going on (I saw something to do with knockout.js, although not 100% sure if that's what's being invoked), and at that point, the code creates a totally new 'input' element in the page, which was not there originally.
Do you know if there's a way to automate these journeys? or does the issue sound familiar so that I could research what I could do from my end?
Thank you!
Upvotes: 0
Views: 303
Reputation: 49910
If there really is no input
element on the page (double check because it's unlikely if knockout.js is being used for it), and it gets added when the use clicks the upload button via JS then there is no "clean" way to test that with Capybara. The only way would be to figure out exactly what JS is being called, by the button press, and use execute_script
to call the JS methods necessary to create the correct input
element on the page and then attach to that.
Upvotes: 0