dro*_*oks 4 ruby cucumber capybara site-prism
我在SitePrism页面中定义了以下元素:
element :type, "select[id='type']"
elements :type_options, "select[id='type'] option"
Run Code Online (Sandbox Code Playgroud)
在我的黄瓜步骤定义中,我有以下代码,根据元素值从选择框中选择一个项目:
@app.new.type_options.each {|name| name.click if name.text.upcase == value.upcase}
Run Code Online (Sandbox Code Playgroud)
我真的不喜欢这个实现,但它在chrome中运行Capybara时效果很好但是当我无头运行它时失败了所以我认为必须有一个备用/更好的方法来选择下拉项目.
理想情况下,我希望能够做类似的事情@app.new_r.r_type.select 'value',但我无法解决如何在SitePrism中做到这一点.
所以,我的第一个问题是,是否有人可以推荐一种优雅的方式从下拉列表中选择一个基于SitePrism值的项目?
我的第二个问题是,任何想法为什么上面的代码在无头运行时失败了?
Gay*_*yle 12
我遇到了类似的问题,我无法选择我想要的选项.我遇到了这个问题,它让我意识到我的问题是你必须将文本而不是值发送到select().
例如,如果我喜欢HTML
<select id="things">
<option value="thing1">The First Thing</option>
<option value="thing2">The Second Thing</option>
<option value="thing3">The Third Thing</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在我的SitePrism :: Page类我有:
element :things, "select[id='things']"
Run Code Online (Sandbox Code Playgroud)
我以为我需要这样做:
@my_page.things.select("thing1")
Run Code Online (Sandbox Code Playgroud)
这不起作用.相反,你必须这样做:
@my_page.things.select("The First Thing")
Run Code Online (Sandbox Code Playgroud)
我知道这与尝试根据您从SitePrism获得的值进行选择略有不同,就像最初被问到的那样.但是我认为关于传递给select()的内容的区别可能对某人有所帮助.