我正在尝试将表单数据从 cucumber 测试发送到 Controller 方法。
我有一个带有登录名和密码字段的表单,以及提交按钮。
表单 View :
<%= text_field_tag 'login', id: 'login-input' %>
<%= password_field_tag 'password', nil, id: 'password-input' %>
<%= submit_tag 'Login', id: 'submit-credentials' %>
在 cucumber 步骤中,我以该形式输入值(未显示登录字段,但类似)。
Then(/^I press "password-input"$/) do
find("#password-input").click
end
Then(/^I enter "myPassword" into the "password-input"$/) do
find("#password-input").text("myPassword")
end
现在登录名和密码值已设置。
然后我按下提交按钮
And(/^I press "submit-credentials"$/) do
find("#submit-credentials").click()
end
我的身份验证方法被调用,但它的参数为空。
当我在网页上正常输入值时,一切正常。为什么 cucumber 版本不起作用?
我所有的 cucumber 步骤都通过了!!所以我很困惑
如何将数据从文本字段发送到 Controller 方法?
谢谢
最佳答案
有几种方法可以interact with forms in Capybara
尝试使用
Then(/^I enter "myPassword" into the "password-input"$/) do
find("#password-input").set("myPassword")
end
代替
Then(/^I press "password-input"$/) do
find("#password-input").click
end
Then(/^I enter "myPassword" into the "password-input"$/) do
find("#password-input").text("myPassword")
end
关于ruby-on-rails - Rails Cucumber 测试 - 将表单数据发送到方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41062423/