2016-06-15 19 views
1

私はキュウリを初めて使っていて、キュウリ/ルビー/カピバラ/セレンのドライバーの設定は簡単です。キュウリ:Ruby Capybaraの定義ステップの書き方

私のようなシナリオ概要があります。私のenv.rbファイル

Given(/^the user is on the test page$/) do 
visit 'http://....' 
end 

When(/^I select my "([^"]*)"$/) do |table| 
select([Country], :from => 'id-of-dropdown') 
click_on('Submit') 
end 

When(/^the testpage is loaded$/) do 
pending # Write code here that turns the phrase above into concrete actions 
end 

Then(/^the "([^"]*)" from UserSetLocation is displayed$/) do |arg1| 
pending # Write code here that turns the phrase above into concrete actions 
end 

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

Capybara.run_server = false 
#Set default driver as Selenium 
Capybara.default_driver = :selenium 
#Set default driver as webkit (browserless) 
#Capybara.javascript_driver = :webkit 
#Set default selector as css 
Capybara.default_selector = :css 

#Syncronization related settings 
module Helpers 
def without_resynchronize 
    page.driver.options[:resynchronize] = false 
    yield 
    page.driver.options[:resynchronize] = true 
end 
end 
World(Capybara::DSL, Helpers) 

私が持っている問題が何であるかである

Feature: Country of user is displayed 
Scenario Outline: CountryCode of User is displayed based on his Country selected. 
Given the user is on the test page 
When I select my "<Country>" 
And the testpage is loaded 
Then the "<CountryCode>" is displayed 

Examples: 
| Country  | CountryCode | 
| Canada  | CA   | 
| United States | US   | 

ステップの定義を正確な構文を使用して、データテーブルの国の列から値を取得します。

次のように動作しますが、このデータシートには数多くの国が含まれている可能性があります。

select("Canada", :from => 'id-of-dropdown') 

おそらく、私のenv.rbに情報がないか、単に正しい構文を使用していないのでしょうか? 私は文字通りオンラインでこのサイトで数日間検索しており、どんな助けでも大歓迎です! ありがとうございます。 Melie

答えて

2

シナリオのアウトラインを使用する場合、テーブルの値はステップ定義に渡されます。それは渡されるテーブルではありません。ステップ:tableを引用との間に捕捉された値であり、

ステップ定義において
When I select my "Canada" 

When I select my "United States" 

When I select my "<Country>" 

は概念的に同じです。それはちょうどStringであることがわかります。

When(/^I select my "([^"]*)"$/) do |table| 
    p table.class 
    #=> String 

    p table 
    #=> "Canada" or "United States" 
end 

あなたはまっすぐselectメソッドにこの値を渡すことができます。

When(/^I select my "([^"]*)"$/) do |country| 
    select(country, :from => 'id-of-dropdown') 
    click_on('Submit') 
end 
+0

すぐに解説して解決していただきありがとうございます。今すぐ動作します。私は確かに学ぶべきことがたくさんある。 – Melie

関連する問題