2013-03-02 76 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