2

現在、次の状況をテストする必要があるシナリオがあります。

  • テキストフィールドに学校名を入力した場合。
  • 次に、そのサブドメインのURLに移動する必要があります

例えば。xyz大学をテキストフィールドに入力すると、xz.lvh.me:3000になります。xyz大学の短縮名はデータベースに保存されているxzです。

ホームページ.feature機能:ホームページ大学のフィールドを確認する必要があります

  Scenario Outline: Fill up universities
    When i fillup university name "<name>"
    Then it should go to their login page "<subdomain>"

  Examples:
    | name |   subdomain |
    | sp College  |  sp  |  

ホームページ.rb

When /^i fillup university name "([^"]*)"$/ do |name|
  visit @@url
  choose('institution_category_school')
  fill_in "search_institution_name", :with => name
  click_button "Go"
end

Then /^it should go to their login page "([^"]*)"$/ do |subdomain|
  #so i need to check that produced url == "#{subdomain}.lvh.me:3000/"
end

以下は私の設定ファイルです。support / env.rb

require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'rspec'

Capybara.run_server = false
Capybara.default_driver = :selenium
Capybara.default_selector = :css

module Helpers
  def without_resynchronize
    page.driver.options[:resynchronize] = false
    yield
    page.driver.options[:resynchronize] = true
  end
end

World(Capybara::DSL, Helpers)

@@url= "http://lvh.me:3000/"

Rails 3.1.1、キュウリ1.1.4、rspec2.8.0を使用

4

1 に答える 1

1

Capybara では、以下を使用してブラウザの現在の URL を取得できます。

current_url

次に、通常の rspec アサーションを使用できます。

current_url.should == "#{subdomain}.lvh.me:3000/"
于 2012-04-25T13:36:48.500 に答える