gpt4 book ai didi

ruby-on-rails-3 - Rails 3 集成测试 - 使用 webrat fill_in 找不到字段

转载 作者:行者123 更新时间:2023-12-04 07:16:11 24 4
gpt4 key购买 nike

我现在正在学习测试,但是 Webrat 遇到了一些问题,无法使用 fill_in 查找表单字段即使我已经验证它在正确的页面上。 Webrat 是否可以使用字段名称或 ID?我曾尝试使用 Ruby 符号和表单名称来访问该字段,但在我的情况下都不起作用。你看到我的实现有什么不正确的吗?

错误信息:

5) Forwarding should forward the user to the requested page after signin
Failure/Error: integration_sign_in(user)
Could not find field: :email

测试代码:
it "should forward the user to the requested page after signin" do
user = Factory(:user)
visit edit_user_path(user)

# The test automatically follows the redirect to the signin page
puts current_url
integration_sign_in(user)

# The test follows the redirect again, this time to users/edit
response.should render_template('users/edit')
end

哪里 integration_sign_inspec_helper.rb
def integration_sign_in(user) 
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
end

表单字段 HTML:
<form action='/sessions' class='mtm' id='sign-in-form' method='post'> 
<input name='authenticity_token' type='hidden' value='iIIqT6bUwiJkpqpgxm5sjAj3egrNcEgeXPsYmbKQ02U='>
<div class='landingSignInForm'>
<label class='mas signin-label' for='email'>E-mail:</label>
<input class="mls ras" id="email" name="email" placeholder="e-mail address" type="text" />
<label class='mas signin-label' for='password'>Password:</label>
<input class="mls ras" id="password" name="password" placeholder="password" type="password" />
<input checked='checked' class='mls mtm' name='remember' type='checkbox' value='permanent'>
<span class='remember-me-label'>Keep me signed in</span>
<input class='mls mvm ram medium silver button' name='submit' type='submit' value='Sign in'>
<a class='forgot-password' href='#'>Forget your password?</a>
</div>
</form>

最佳答案

您是否尝试过使用 css 选择器作为 ID 而不是仅传递匹配的符号?我尝试简要阅读 webrat 源代码以确定它是否在内部将符号视为字符串,想知道这是否是您的问题。我找不到任何使用 fill_in :symbol 的 webrat 语法示例只有fill_in 'string'
尝试这个:

def integration_sign_in(user) 
fill_in 'email', :with => user.email
fill_in 'password', :with => user.password
click_button
end

或您的 id 的 css 选择器路由:
def integration_sign_in(user) 
fill_in '#email', :with => user.email
fill_in '#password', :with => user.password
click_button
end

关于ruby-on-rails-3 - Rails 3 集成测试 - 使用 webrat fill_in 找不到字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5326256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com