Cucumber 水豚如何测试下拉列表中的禁用选项
我是水豚的新手,正在尝试编写一个测试,其中下拉列表中的默认选项将根据用户在上一页中单击的链接而改变。e、 g.单击link1,则link1将是默认选项 我在网上发现有人说要在下拉列表中测试禁用选项,但我仍然无法让它工作Cucumber 水豚如何测试下拉列表中的禁用选项,cucumber,capybara,Cucumber,Capybara,我是水豚的新手,正在尝试编写一个测试,其中下拉列表中的默认选项将根据用户在上一页中单击的链接而改变。e、 g.单击link1,则link1将是默认选项 我在网上发现有人说要在下拉列表中测试禁用选项,但我仍然无法让它工作 Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector| with_scope(selector) do field_l
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
根据您的描述,我假设您指的是选中的选项,而不是禁用的选项。在水豚鱼身上做这件事
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中检查禁用的选项,您可以这样做
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命令同步