如何使用SitePrism gem从下拉菜单中选择一个选项并测试该选项是否已被选中

时间:2015-10-19 22:03:22

标签: html ruby cucumber site-prism

我已经定义了一个SitePrism页面,其中包含带选项的select标签(在我的页面上创建一个下拉菜单)。

在我的黄瓜步骤中,我试图设置它以便从下拉菜单中选择其中一个选项,但似乎无法这样做。

这是我的设置:

class ViewBudgetPage < SitePrism::Page
  set_url '/budget{/id}'

   element :date,            "input[name='cost_date']"
   element :description,     "input[name='cost_desc']"
   element :price,           "input[name='cost_price']"
   elements :categories,     "select[id='categories_list']"
   element :add_cost_button, "button[type='submit']"

在我的步骤中,我有:

When "I fill in the form to create a new cost" do
    @current_budget_page.date.set '1-Aug-2010'
    @current_budget_page.description.set 'some description'
    @current_budget_page.price.set '10'
    @current_budget_page.categories.select "Donations"
end

我的页面看起来像:

<div class='form-group'>
    <select class="form-control" id="categories_list"name='model_number'><option value='unselected'> Please select a category </option>   
<% @budget_wrapper.all_categories.each do |cat_name| %>
<option value='<%=cat_name%>'><%=cat_name%></option>
      <%end%>
     </select>
</div>

问题是呼叫&#34;选择&#34;在步骤中的元素不起作用!它抱怨: ArgumentError异常:参数数量错误(1表示0)

调用没有参数的select工作不会抱怨

@current_budget_page.categories.select

,但那不是我想要的。我认为从列表中获取第一个元素(默认值)。

我希望能够在我的步骤中说: 从页面的下拉菜单中选择一个特定的元素。

有什么帮助吗?

感谢。

0 个答案:

没有答案