我尝试进行Selenium-Acceptancetest'搜索结果列表'与RSpec spec
我很乐意为开始思考作为编码员而获得帮助;我是一名手动测试员。
我现在的问题是:
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>
非常感谢!
我的测试文件:
# 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">]
答案 0 :(得分:0)
给出错误消息:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
我怀疑你的问题是一个缺失的括号。正常的Rspec语法是
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
虽然我猜你需要在后半部分调用一个尺寸函数,也可以使用find elements。也许this也会对你有用。