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.
我主要使用Ruby,Capybara和SitePrism的测试框架,直到现在我成功使用'attach_file(input_element,File.path)'方法。
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.
我现在已经转移到另一个项目,他们已经有了这个页面,其中有一个'上传按钮'但是在第一次加载时页面中没有任何'input'元素(检查源代码,也没有隐藏元素,即,“输入”根本不出现在页面中。发生了什么事情当用户点击“上传”按钮时,会出现一个窗口弹出窗口,他们可以选择他们的文件,当他们选择那个时,似乎有一些javascript正在进行(我看到有些事情要做knockout.js,虽然不是100%确定是否正在被调用),并且在那时,代码在页面中创建了一个全新的“input”元素,这个元素最初并不存在。
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!
1 个解决方案
#1
0
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.
如果页面上确实没有输入元素(仔细检查,因为如果使用knockout.js它不太可能),并且当用户通过JS点击上传按钮时它会被添加,那么就没有“干净”的方法来测试与Capybara一起。唯一的方法是通过按下按钮确定要调用的JS,并使用execute_script调用在页面上创建正确的输入元素然后附加到该页面所需的JS方法。
#1
0
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.
如果页面上确实没有输入元素(仔细检查,因为如果使用knockout.js它不太可能),并且当用户通过JS点击上传按钮时它会被添加,那么就没有“干净”的方法来测试与Capybara一起。唯一的方法是通过按下按钮确定要调用的JS,并使用execute_script调用在页面上创建正确的输入元素然后附加到该页面所需的JS方法。