我正在使用Cucumber和watir-webdriver为我的应用程序编写自动化测试。我的目标是清除以下多选列表中默认选择的“ADD”和“CHG”选项,然后重新选择ADD选项。
<select name="actions_arr" id="actions_arr" style="width: 190px; height: 110px;" multiple="multiple">
<option value="Any">
<option value="CHG">
<option value="ADD">
<input name="_actions_arr" type="hidden" value="1"/>
我编写了以下ruby函数(包括一些诊断调试打印命令)来清除选择列表。在这种情况下,变量 action_type = ADD。问题是,当我在无头模式下运行浏览器时,我无法清除所选的选项,并且我得到一个watir异常,说该列表不是多选列表,即使它真的是。但是,如果我使用IE8浏览器的本地实例驱动应用程序,则选择列表会被识别为多选列表,我可以清除获得预期结果的选项。
def set_action_type(action_type)
s = @browser.div(:id => 'tabs').frame(:id => 'container').div(:id => 'sidebar').select_list(:id => 'actions_arr')
puts "Is the combo list visible?"
puts s.visible?
puts "is the list a multi-select list?"
puts s.multiple?
s.clear
puts "Has the ADD option been selected?"
puts s.selected?action_type
puts "Has the CHG option been selected?"
puts s.selected? 'CHG'
puts s.selected_options
end
1)使用无头浏览器驱动应用程序时,我得到以下输出:
Is the combo list visible?
true
is the list a multi-select list?
false
Watir::Exception::Error: you can only clear multi-selects
./features/step_definitions/atom_steps.rb:43:in `set_action_type'
./features/step_definitions/atom_steps.rb:169:in `/^I select the "(.*?)" action type$/'
E:\ATOM_TEST\AcceptanceTest\atom\features\filtering.feature:10:in `And I select the "ADD" action type'
1 scenario (1 failed)
5 steps (1 failed, 4 passed)
0m32.188s
Process finished with exit code 1
2)当驱动IE8浏览器的本地实例时,我得到以下输出是正确的(忽略方案失败消息,因为所有测试步骤实际通过):
Is the combo list visible?
true
is the list a multi-select list?
true
Has the ADD option been selected?
false
Has the CHG option been selected?
false
[]
1 scenario (1 failed)
5 steps (5 passed)
2m1.766s
Process finished with exit code 1
我的问题是
关于2)我正在尝试使用selenium webdriver中的actionbuilder类来尝试发送CONTROL和鼠标单击选择命令,以模拟用户通过UI清除所选选项。
请注意我使用的以下代码以无头模式启动浏览器:
require 'watir-webdriver'
require 'selenium/server'
include Selenium
Before do
@server = Selenium::Server.new("selenium-server-standalone-2.0b1.jar", :background => true)
@server.start # run your tests
capabilities = WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
@browser = Watir::Browser.new(:remote, :url => 'http://127.0.0.1:4444/wd/hub', :desired_capabilities => capabilities)
#Uncomment the below line and comment out the above lines if you don't want to run in headless mode
#@browser = Watir::Browser.new :ie
end
After do
@browser.link(:text => 'Logout').click
@browser.close
@server.stop
end
答案 0 :(得分:0)
感谢@JustinKo将 selenium-server-standalone-2.0b1.jar 升级到最新版本 selenium-server-standalone-2.44.0.jar 现在获得正确的输出如下,无异常被引发。
Is the combo list visible?
true
is the list a multi-select list?
true
Has the ADD option been selected?
false
Has the CHG option been selected?
false
[]
1 scenario (1 passed)
6 steps (6 passed)
0m33.203s
Process finished with exit code 0