RSpec:无法验证搜索结果页面上有超过 5 个 Btns [英] RSpec: Cant Verify there are more than 5 Btns on Search Result Page
本文介绍了RSpec:无法验证搜索结果页面上有超过 5 个 Btns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 RSpec 规范
- 我的问题是它应该验证按钮详细信息"的计数
我很乐意获得帮助以开始作为一名程序员思考;我仍然是一名手动测试员.
I would be happy to get help for start thinking as a coder; i am a manual tester stil.
我现在的问题是:
Method Error
Failure/Error: expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 4)
NoMethodError:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
- 来源:在解决这个问题的路上,我试图修改 this 并且我找到这个但它不起作用
- Sources: On my way to resolve the issue I tried to modify this and I found this But its not working
幸好还在!
我的测试文件:
# coding: utf-8
puts "this is #{File.basename(__FILE__)}"
extend RSpec::Expectations
extend RSpec::Matchers
describe 'SEL' do
before(:each) do
@driver = loadDriver()
end
after(:each) do
@driver.quit
end
it 'test_Page (SEL)' do
#get the page
...
#do input keyword 'Restaurant'
...
#click submit
...
#(Works!) temp Validation1: Is there a "Btn Details" in SearchResultList?
expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").displayed?)
#(Works not!) Validation: Are there more than "5 Btns Detail"
expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
end
end
<小时>
第一次回答后更新:
鉴于我使用
expect(@driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
它遇到了那个错误:
Failure/Error: expect(@driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
expected: > 0
got: [#<Selenium::WebDriver::Element:0xa6219008 id="a2a2c83a-e52d-4464-81ec-4fce07ccc0b6">, #<Selenium::We...64378279">, #<Selenium::WebDriver::Element:0x..f90cc8d0e id="de990e21-eecf-48db-873b-76515dba7c3e">]
推荐答案
鉴于错误信息:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
我怀疑您的问题是缺少括号.正常的 Rspec 语法是
I suspect your issue is a missing bracket. Normal Rspec syntax is
expect(something).to eq(some value).
我想你错过了右括号
expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
这应该更像是:
expect(@driver.find_element(:xpath, "//a[contains(text(),'Details')]")).to be > 5
虽然我猜你需要在后半部分调用 size 函数,也可能使用 查找元素.也许这个 也会对你有用.
Although I might guess you need to call a size function on the latter part as well as maybe use find elements. Maybe this will also be useful for you.
这篇关于RSpec:无法验证搜索结果页面上有超过 5 个 Btns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文