如何使用"输入密钥"来测试表单提交?通过水豚使用poltergeist

时间:2014-07-14 19:28:27

标签: angularjs capybara poltergeist

重复标题,我的问题是如何使用poltergeist通过capybara使用“Enter Key”测试表单提交。换句话说,我希望当我填写用户名,密码然后在任一输入时按“Enter”我将提交表格。从我所知道的,poltergeist通过“send_keys”实现了这一点。但是我目前的测试:

When(/^I log in with enter key$/) do
  visit_login
  fill_in "app-email", :with => admin_user.email
  fill_in "app-password", :with => admin_user.password
  login = find("#app-password")
  login.native.send_key :Enter
end

使用以下(原始)代码,该代码使用ng-click。我希望上面的代码在下面的代码中失败,因为下面的代码无法在浏览器中输入并提交表单。这是ng-click代码:

%form{name: "form"}
  %input#app-email{name: "email", "ng-model" => "email", type: 'email'}
  %input#app-password{name: "password", "ng-model" => "password", type: "password"}
  %a.btn.btn-primary.login-btn#app-login{"ng-click" => "login(email, password)"} LOG IN

这是带有ng-submit的代码,这两个都是手动和测试的:

%form{name: "form", "ng-submit" => "login(email, password)"}
  %input#app-email{name: "email", "ng-model" => "email", type: 'email'}
  %input#app-password{name: "password", "ng-model" => "password", type: "password"}
  %input.btn.btn-primary.login-btn#app-login{type: "submit", value: "LOG IN"}

有一个相当冗长的讨论,要让它在这里工作:Is there a way to send key presses to Webkit using Capybara?。但是,我无法修改任何适用于我的解决方案。

0 个答案:

没有答案