0

我有 6 个产品页面,出于功能测试的目的,它们几乎相同。它们的区别仅在于我目前不做任何事情的描述和图像。这是我的 current_setup:基页:product_page.rb

class ProductPage
  button(:add_fruit_proceed, :id => add_fruit)
  text_field(:fruit_quantity, :id => fruit_quantity)
end

产品页面看起来都类似于:apple_page.rb

class ApplePage < ProductPage
  page_url "#{domain}/fruit/apple"
end

有没有办法整合所有这些,以便我只有 product_page.rb?我需要 page_url,因为我在测试中确实使用了 visit(ApplePage)。

4

1 回答 1

2

page_url可以改为:

page_url "#{domain}/<%=params[:category]%>/<%=params[:type]%>"

页面对象 gem 使用 ERB 允许您创建页面 url 模板,该模板允许稍后替换参数 - 即在调用访问时。

要访问该页面,您必须指定类别并输入using params

visit ProductPage, using_params: {category: 'fruit', type: 'apple'} do |page|
  # Do stuff with the domain/fruit/apple page
end
于 2014-01-27T18:55:58.330 回答