我有一个带有适当标签的字段,我可以用水豚填写没有问题:
fill_in 'Your name', with: 'John'
Run Code Online (Sandbox Code Playgroud)
我想在填写它之前检查它的值,但无法弄明白.
如果我fill_in在以下行之后添加:
find_field('Your name').should have_content('John')
Run Code Online (Sandbox Code Playgroud)
该测试失败,尽管之前的填充工作正如我通过保存页面验证的那样.
我错过了什么?
页面网址就像/people?search=name
我使用current_path的水豚方法一样/people只返回.
current_path.should == people_path(:search => 'name')
Run Code Online (Sandbox Code Playgroud)
但它没有说
expected: "/people?search=name"
got: "/people"
Run Code Online (Sandbox Code Playgroud)
我们怎么能通过?有没有办法做到这一点?
我正在使用Rspec和Capybara.
我怎么写一个步骤来检查checkbox?我已经尝试check了价值,但它找不到我的checkbox.我不知道该怎么做,因为我实际上有相同的ID具有不同的值
这是代码:
<input id="cityID" type="checkbox" style="text-align: center; opacity: 0;" value="61" name="cityID">
<input id="cityID" type="checkbox" style="text-align: center; opacity: 0;" value="62" name="cityID">
<input id="cityID" type="checkbox" style="text-align: center; opacity: 0;" value="63" name="cityID">
Run Code Online (Sandbox Code Playgroud) 在这种情况下如何单击第一个链接:
<div class="item">
<a href="/agree/">Agree</a>
</div>
<div class="item">
<a href="/agree/">Agree</a>
</div>
Run Code Online (Sandbox Code Playgroud)
within ".item" do
first(:link, "Agree").click
end
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching css ".item"
Run Code Online (Sandbox Code Playgroud)
没有within我得到这个错误:
Failure/Error: first(:link, "Agree").click
NoMethodError:
undefined method `click' for nil:NilClass
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Capybara(2.1.0)从下拉菜单中选择一个项目.
我想按编号选择(意思是选择第二个,第三个等选项).
我用Google搜索疯狂尝试各种各样的东西,但没有运气.
我可以通过使用值来选择它:
find("option[value='4c430d62-f1ba-474f-8e8a-4452c55ea0a8']").click
Run Code Online (Sandbox Code Playgroud)
但我不想使用那种方法b/c值会改变,这将使我的测试变得脆弱.
下拉列表的HTML是:
<td class="value">
<select name="organizationSelect" id="organizationSelect" class="required">
<option value="NULL">Choose...</option>
<option value="4c430d62-f1ba-474f-8e8a-4452c55ea0a8"> Institution1</option>
<option value="e1a4efa7-352d-410a-957e-35c8a3b92944"> Institution / test</option>
</select>
</td>
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
option = find(:xpath, "//*[@id='organizationSelect']/option[2]").text
select(option, :from => organizationSelect)
Run Code Online (Sandbox Code Playgroud)
但它会导致此错误:
Ambiguous match, found 2 elements matching option "Institution" (Capybara::Ambiguous)
Run Code Online (Sandbox Code Playgroud)
那么如何从下拉列表中选择第一个,第二个,第三个等选项(使用Capybara)?
有关如何修复的任何建议?
gem install capybara-webkit -v '0.11.0'
Building native extensions. This could take a while...
ERROR: Error installing capybara-webkit:
ERROR: Failed to build gem native extension.
/home/durrantm/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
sh: qmake: not found
Gem files will remain installed in /home/durrantm/.rvm/gems/ruby-1.9.3-p194/gems/capybara-webkit-0.11.0 for inspection.
Results logged to /home/durrantm/.rvm/gems/ruby-1.9.3-p194/gems/capybara-webkit-0.11.0/./gem_make.out
Run Code Online (Sandbox Code Playgroud) 我在HTML中有以下两个元素
<a href="/berlin" >Berlin</a>
<a href="/berlin" >Berlin Germany </a>
Run Code Online (Sandbox Code Playgroud)
我试图通过使用以下Capybara方法找到元素
find("a", :text => "berlin")
Run Code Online (Sandbox Code Playgroud)
上面将返回两个元素,因为它们都包含文本柏林.
有没有办法匹配Capybara的确切文字?
如何解决Capybara的歧义?出于某种原因,我需要在页面中使用相同值的链接,但由于我收到错误,因此无法创建测试
Failure/Error: click_link("#tag1")
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching link "#tag1"
Run Code Online (Sandbox Code Playgroud)
我无法避免这种情况的原因是因为设计.我正在尝试使用右侧的推文/标签和页面左侧的标签重新创建推特页面.因此,相同的链接页面不可避免地出现在同一页面上.
我想做以下但不能由于fill_in的性质期望定位器作为第一个参数.
find(:css, "input[id$='donation_pledge_hundreds']").fill_in :with => "10"
Run Code Online (Sandbox Code Playgroud)
我也尝试过
element = find(:css, "input[id$='donation_pledge_hundreds']")
fill_in element.<method> , :with => "10"
Run Code Online (Sandbox Code Playgroud)
但是没有方法可以返回任何数据来识别fill_in元素.
有关通过正则表达式查找字段以与fill_in一起使用的最佳方法的任何想法吗?
我不能让capybara与rspec合作.它给了我这个错误:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil>
Run Code Online (Sandbox Code Playgroud)
我知道有很多关于此的帖子,但没有解决方案对我有用.他们中的大多数涉及的规格不在/ spec/features中 - 我的是.
首先是错误:
$bundle exec rspec spec
F
Failures:
1) security signs users in
Failure/Error: visit "/sessions/new"
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil>
# ./spec/features/security_spec.rb:4:in `(root)'
Finished in 0.006 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/security_spec.rb:3 # security signs users in
Run Code Online (Sandbox Code Playgroud)
我认为重要的是要注意,起初我使用URL Helper'new_sessions_path'并且它一直给我一个错误undefined local variable or method 'new_sessions_path'.我知道这是有效的,因为:
$ rake routes
logout_sessions GET /sessions/logout(.:format) sessions#logout
sessions POST /sessions(.:format) sessions#create
new_sessions GET /sessions/new(.:format) sessions#new
contracts POST /contracts(.:format) …Run Code Online (Sandbox Code Playgroud)