我有一个包含两种表单的页面。这是一种设置形式。我已经给了一切css id只是为了让它们易于选择。
%form#mnic_form
.datagrid
%table
%thead
%tr
%th{:colspan => "2"}
= "(eth0 - Management) Port Settings (#{@a.get_management_nic["mac"]})"
%tbody#managementnic
%tr
%td
DHCP:
%td
%input#dhcpon1{:type => "radio", :name => "dhcp", :value => "true", :checked => @a.get_management_nic["dhcp"], :onclick => "dhcpHandler('management')"} Enabled
%br
%input#dhcpoff1{:type => "radio", :name => "dhcp", :value => "false", :checked => !@a.get_management_nic["dhcp"], :onclick => "dhcpHandler('management')"} Disabled
%tr
%td
IP Address:
%td
%input#ip1{:type => "text", :name => "ip", :value => @a.get_management_nic["ip"], :onblur => "IPHandler('#ip1')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
Subnet Mask:
%td
%input#subnet1{:type => "text", :name => "subnet", :value => @a.get_management_nic["subnet"], :onblur => "IPHandler('#subnet1')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
Gateway:
%td
%input#gateway1{:type => "text", :name => "gateway", :value => @a.get_management_nic["gateway"], :onblur => "IPHandler('#gateway1')" }
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
DNS Servers:
%td
%input#dyndns1{:type => "checkbox", :name => "dynamicDNS", :value => "true", :checked => @a.get_management_nic["dynamicDNS"], :onclick => "dynamicDNSHandler('management')"}
Automatically assign DNS from DHCP Server
%tr
%td
DNS 1:
%td
%input#dns11{:type => "text", :name => "dns1", :value => @a.get_management_nic["dns1"], :onblur => "IPHandler('#dns11')" }
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
DNS 2:
%td
%input#dns21{:type => "text", :name => "dns2", :value => @a.get_management_nic["dns2"], :onblur => "IPHandler('#dns21')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%input#mnic_submit{:type => "button", :value => "Save", :onclick => "submitMNic()"}
%form#vnic_form
.datagrid
%table
%thead
%tr
%th{:colspan => "2"}
= "(eth1 - Video) NIC Port Settings (#{@a.get_video_nic["mac"]})"
%tbody#videonic
%tr
%td
DHCP:
%td
%input#dhcpon2{:type => "radio", :name => "dhcp", :value => "true", :checked => @a.get_video_nic["dhcp"], :onclick => "dhcpHandler('video')"} Enabled
%br
%input#dhcpoff2{:type => "radio", :name => "dhcp", :value => "false", :checked => !@a.get_video_nic["dhcp"], :onclick => "dhcpHandler('video')"} Disabled
%tr
%td
IP Address:
%td
%input#ip2{:type => "text", :name => "ip", :value => @a.get_video_nic["ip"], :onblur => "IPHandler('#ip2')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
Subnet Mask:
%td
%input#subnet2{:type => "text", :name => "subnet", :value => @a.get_video_nic["subnet"], :onblur => "IPHandler('#subnet2')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
Gateway:
%td
%input#gateway2{:type => "text", :name => "gateway", :value => @a.get_video_nic["gateway"], :onblur => "IPHandler('#gateway2')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
DNS Servers:
%td
%input#dyndns2{:type => "checkbox", :name => "dynamicDNS", :value => "true", :checked => @a.get_video_nic["dynamicDNS"], :onclick => "dynamicDNSHandler('video')"}
Automatically assign DNS from DHCP Server
%tr
%td
DNS 1:
%td
%input#dns12{:type => "text", :name => "dns1", :value => @a.get_video_nic["dns1"], :onblur => "IPHandler('#dns12')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
DNS 2:
%td
%input#dns22{:type => "text", :name => "dns2", :value => @a.get_video_nic["dns2"], :onblur => "IPHandler('#dns22')"}
%img.spinner{:src => '/img/busy_spinner.gif', :style => "display: none", :height => "15"}
%tr
%td
%td
%p All multicast routed on this interface
%input#vnic_submit{:type => "button", :value => "Save", :onclick => "submitVNic()"}
现在,当我使用水豚进行测试时,我尝试了这两个功能:
page.choose('dhcpoff1')
page.choose('dhcpoff2')
第一个完美无缺,第二个无效。这不应该难以弄清楚,但我完全陷入困境。几个小时都在盯着它看。我很欣赏你可能有的任何见解。
function dhcpHandler(m_or_v) {
var tmp = (m_or_v === "management") ? tmp = $('#managementnic > tr > td > input') : tmp = $('#videonic > tr > td > input');
if (tmp[0].checked) {
tmp[2].disabled = true;
tmp[3].disabled = true;
tmp[4].disabled = true;
}
else {
tmp[2].disabled = false;
tmp[3].disabled = false;
tmp[4].disabled = false;
}
}
更多测试。上面有控制器方法,所以我只想说页面选择dhcpon2,ip2,gateway2和subnet2全部禁用。
我试图运行page.choose('dhcpoff2')
并让它选择dhcpoff2,然后触发dhcpHandler()取消禁用3个字段。有效的解决方法是page.execute_script("$('#dhcpoff2').click()")
,但这太难以忍受了。目前我有它在硒失败(2.48.1,capybara 2.5.0),并在poltergeist工作... ???所以更具体一点,这是一个测试:
page.choose('dhcpoff2')
#page.execute_script("$('#dhcpoff2').click()")
assert !find('#ip2')["disabled"]
如果我们评论第2行(贫民窟工作)它会以吵闹者为驱动程序,但不以硒作为驱动程序。
最后,这里是我正在使用的驱动程序设置,交换哪些行被注释以在poltergeist和selenium之间切换:
include Capybara::DSL
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: false, phantomjs: "C:/Ruby22-x64/bin/phantomjs.exe")
end
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
#Capybara.default_driver = :poltergeist
#Capybara.javascript_driver = :poltergeist
Capybara.default_max_wait_time = 10
Capybara.ignore_hidden_elements = false