0
如何在此rspec测试中执行我的JavaScript函数addRows()?该功能不会在测试中运行。Rails 4,Selenium执行javascript事件
我的RSpec的测试
context 'pressing alt+m, ' do
it 'appends hello to the dom', :js => true do
visit welcome_path
page.execute_script("return addRows(keypressdown = 17, keypressdown = 77);")
expect(page).to have_content("hello")
end
end
keypressListener.js文件
function addRows(event) {
event = event || window.event;
if(event.keyCode == 17 && event.keyCode == 77) {
document.body.append("hello");
}
}
运行轨道服务器,并手动按下Alt + M这个网页上运行的addRows()函数,但测试不运行该功能。
根据你的建议,作为“一个元素代表页面上的一个单一元素”,我使用了变量= page.find'body',然后调用variable.send_keys [:alt,'m']使测试通过。谢谢!!!! – wsgb
优秀!我从你的经验中添加了我的答案。 –