获得;rspec::ExpectationNotMetError“;在尝试为谷歌搜索运行cucumber测试时
今天是我第一天吃红宝石和黄瓜。我在网上发现了这个非常有用的示例代码,我正在努力使它工作,但我在最后一步被卡住了 这是我的功能文件:获得;rspec::ExpectationNotMetError“;在尝试为谷歌搜索运行cucumber测试时,rspec,cucumber,Rspec,Cucumber,今天是我第一天吃红宝石和黄瓜。我在网上发现了这个非常有用的示例代码,我正在努力使它工作,但我在最后一步被卡住了 这是我的功能文件: Feature: 'When I go to the Google search page, and search for an item, I expect to see some reference to that item in the result summary.' Scenario: Given that I have gone to the
Feature:
'When I go to the Google search page, and search for an item,
I expect to see some reference to that item in the result summary.'
Scenario:
Given that I have gone to the Google page
When I add "search" to the search box
And click the Search Button
Then "search" should be mentioned in the results
以下是步骤定义:
Given /^that I have gone to the Google page$/ do
@browser = Selenium::WebDriver.for :firefox
@browser.navigate.to 'http://www.google.com'
end
When /^I add "(.*)" to the search box$/ do |item|
@browser.find_element(:name, 'q').send_keys(item)
end
When /^click the Search Button$/ do
@browser.find_element(:name, 'btnG').click
end
Then /^"(.*)" should be mentioned in the results$/ do |item|
@browser.title.should include(item)
@browser.quit
end
我已经创建了一个env.rb文件:
require 'selenium-webdriver'
require 'rspec/expectations'
当我尝试运行此操作时,我得到以下与Rspec预期错误相关的错误:
Scenario: # features\GoogleSearch.feature:5
Given that I have gone to the Google page # features/step_definitions
/Search_steps.rb:1
When I add "Sogeti" to the search box # features/step_definitions
/Search_steps.rb:6
And click the Search Button # features/step_definitions
/Search_steps.rb:10
Then "Sogeti" should be mentioned in the results # features/step_definitions
/Search_steps.rb:14
expected "Google" to include "Sogeti" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/Search_steps.rb:15:in `/^"(.*)" should be mentioned in the results$/'
features\GoogleSearch.feature:9:in `Then "Sogeti" should be mentioned in the results'
Failing Scenarios:
cucumber features\GoogleSearch.feature:5 # Scenario:
我已经安装了rspecgem并将其包含在env.rb文件中,但我无法使其正常工作。您能帮我吗?提前感谢。您需要调试测试。查看selenium文档,了解如何截图页面,并在行不通之前截图。例外情况是,没有找到您希望在页面上看到的内容。在最后一步中,您试图验证什么?步骤名称表示您要检查搜索结果,而代码表示您正在尝试检查页面的标题。我尝试了当前url而不是标题,结果成功:)。无论如何谢谢你的帮助。