我是Capybara的新手,我正在尝试编写一个测试,其中下拉列表中的默认选项将根据用户在上一页中单击的链接而改变。例如单击link1,然后link1将成为默认选项。
我发现网上有人说要在下拉菜单中测试残疾选项,但是我仍然无法让它工作。
Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
with_scope(selector) do
field_labeled(field).find(:xpath, ".//option[@selected = 'selected'][text() = '#{value}']").should be_present
end
end
答案 0 :(得分:1)
根据您的描述,我假设您的意思是selected
选项,而不是disabled
选项。在Capybara这样做是
expect(page).to have_select('id, name, placeholder or label text of select', selected: 'text of selected option')
在黄瓜步骤中使用它可能会成为范围可能
Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
within(selector) do
expect(page).to have_select(field, selected: value)
end
end
你会称之为。
Then "California" should be selected for "State" within "#user_profile"
如果您确实想在选择中检查禁用选项,可以像
那样进行select = find(:select, 'id, name, placeholder or label text of select')
expect(select).to have_selector(:option, 'text of disabled option', disabled: true)
答案 1 :(得分:0)
示例:
And(/^All segments in this area need to be subject to the product (\d+) see it$/) do
area=find_by_id('temelGostergeler')
number=area.all("div#urunTab.caption[style='display: none;']").size
print "All of "
expect(number).to eq 0
if
number==1
number="No product"
else
number="There are product"
end
p number
end
如果需要,您可以与expect命令同步。