登录时设计、Cucumber 和多个 ID - 注册

发布于 2024-10-07 03:52:20 字数 2193 浏览 0 评论 0原文

我遇到以下问题:

我的整个网站上都有一个登录表单(请参阅 https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in- your-app):

# application.html.haml
...
= form_tag new_user_session_path do
  = text_field_tag 'user[email]'
  = password_field_tag 'user[password]'
  %button Login

我想用黄瓜测试填写我的注册表:

# register#new.html.haml
= semantic_form_for resource, :url => registration_path(resource_name) do |f|
  = f.inputs do
    = f.input :email, :required => true
    = f.input :password, :required => true
    = f.input :password_confirmation, :required => true
    = commit_button("Registrierung absenden")

但现在有一个问题 - 我的页面上有两个字段具有相同的 attribute-id: user_email

当我尝试填写注册表单

# registration_steps.rb
When /^I fill in registration data$/ do |param|
  # this one selects the wrong form - loginform instead of registration form
  fill_in("user_email", :with => "blabla") 
end

的字段属性 ID 相同,“fill_in”选择了错误的输入...

我如何更改 ID 以与设备一起使用?对我来说似乎太复杂了..

我正确地指出了我的问题吗?

更新

这是我呈现的注册网站的一部分:

<html>
....
<!-- you see that both forms contain fields with the same ids! -->
<!-- so when i test f.e. with fill_in("user_login", :with => "123")
     then the wrong form will be filled out! -->
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
    <input id="user_login" name="user[login]" size="30" type="text" />
    <input id="user_password" name="user[password]" size="30" type="password" />
    <input type="submit" value="anmelden" name="commit">
</form>
...
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
    <input id="user_login" name="user[login]" size="30" type="text" />
    <input id="user_password" name="user[password]" size="30" type="password" />
    <input type="submit" value="anmelden" name="commit">
</form>
...
</html>

I'm having the following problem:

I have a login form on my entire site (see https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app):

# application.html.haml
...
= form_tag new_user_session_path do
  = text_field_tag 'user[email]'
  = password_field_tag 'user[password]'
  %button Login

I want to test with cucumber to fill out my registration form:

# register#new.html.haml
= semantic_form_for resource, :url => registration_path(resource_name) do |f|
  = f.inputs do
    = f.input :email, :required => true
    = f.input :password, :required => true
    = f.input :password_confirmation, :required => true
    = commit_button("Registrierung absenden")

But now there is a problem - there are two fields on my page with the same attribute-id: user_email

When I try to fill the registration form with

# registration_steps.rb
When /^I fill in registration data$/ do |param|
  # this one selects the wrong form - loginform instead of registration form
  fill_in("user_email", :with => "blabla") 
end

the attribute-ids of the fields are the same and "fill_in" selects the wrong input...

How could I change the ids to work with devise? Seems too much complex for me..

Did I pointed out my problem correctly?

UPDATE

This is a part of my rendered registration site:

<html>
....
<!-- you see that both forms contain fields with the same ids! -->
<!-- so when i test f.e. with fill_in("user_login", :with => "123")
     then the wrong form will be filled out! -->
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
    <input id="user_login" name="user[login]" size="30" type="text" />
    <input id="user_password" name="user[password]" size="30" type="password" />
    <input type="submit" value="anmelden" name="commit">
</form>
...
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
    <input id="user_login" name="user[login]" size="30" type="text" />
    <input id="user_password" name="user[password]" size="30" type="password" />
    <input type="submit" value="anmelden" name="commit">
</form>
...
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十二 2024-10-14 03:52:20

解决了使用 with_scope("123") 的问题

with_scope("#user_new_form") do
    fill_in("user_email", :with => "123")
end

Solved the problem with using with_scope("123")

with_scope("#user_new_form") do
    fill_in("user_email", :with => "123")
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文