2013-03-02 114 views
2

我是新來的黃瓜,我試圖找到定義功能的最佳方式。黃瓜 - 多語言站點的功能

我需要測試多種語言的網站,所以我想要測試的功能總是相同的,但作爲語言不同,我需要在頁面中查找的文本可能會有所不同。這大概就是我想做的事:

Scenario Outline: Browse through category from the home page 
    Given I am on the <country> home page 
    When I browse categories 
    Then I should get the browse category page 

Examples: 
    | country | 
    | UK  | 
    | IT  | 
    | US  | 

我沒有指定類別中的特徵描述本身值,因爲:

  1. 我希望能夠讀類別從我的數據庫,所以每當我添加/刪除一個我並不需要修改測試本身
  2. 想象一下,有10個國家20個類別中相同的特徵文件......這將是一個爛攤子
  3. 爲了避免2我可以替每個國家的特徵文件......但後來我不得不復制並粘貼N次相同的特徵描述

我想過打電話從其他步驟的一個步驟解。像下面的僞代碼:

When /^I browse categories$/ do 
    on CURRENT_HOME_PAGE do |page| 
    page.categories_list.each do |category| 
     ....visit category page.... 
     ....call "Then I should get the browse category page" step... 
     ....go back to CURRENT_HOME_PAGE.... 
    end 
    end 
end 

我不確定這是最好的最佳解決方案。大多數人也不贊成從步驟中調用步驟。我個人並不喜歡它,因爲我不喜歡將混合步驟和特徵定義的想法。

回答

0

那麼調用ruby方法而不是步驟定義並使用Cucumber實例變量呢?

我的意思是這樣的:

Given /^I am on the (\w+) home page$/ do |country| 
    @country = country # use Cucumber instance variable (it will be available in next steps of this scenario) 
end 

When /^I browse categories$/ do 
    # read expected categories from DB for @country 
    # visit Browse Categories page for @country 
    # check that correct categories are shown 
    expected_categories.each do |category| 
    # visit category page 
    # check that correct category page for @country is shown 
    end 
end 
+0

很好,謝謝!這聽起來像我所需要的。我在這裏實施了一個草案:[link](https://github.com/barbasa/ui_testing)。如果你在代碼中看到瘋狂的東西,不要尖叫,我剛剛開始使用Ruby和Cucumber :) – barbasa 2013-03-02 14:06:21

+0

@barbasa你期望我用這段代碼做什麼? – 2013-03-02 18:14:14

+0

什麼都沒有......我只是想過把它張貼出來,以防其他人有同樣的問題,並希望看到整個實施。 – barbasa 2013-03-03 17:46:43