2
votes

I am using Cucumber and watir-webdriver to write automated tests for my application. My objective is to clear the default selected "ADD" and "CHG" options in the following multi select list and then re-select the ADD option.

<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"/>

I have written the following ruby function (including some diagnostic debug print commands) to clear the select list. In this case the variable action_type = ADD. Issue is that when I run the browser in headless mode I cannot clear the selected options and I get a watir exception saying that the list is not a multi select list even htouhg it really is. However if I drive the app using a local instance of the IE8 browser, the select list is recognised as a multi select list and I can clear the options getting the expected results.

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) When driving the application using a headless browser I get the following output:

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) When driving a local instance of the IE8 browser I get the following output which is correct (ignoring the scenario fail message as all test steps actually pass):

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

The question I have is

  1. How can I get the above multi-select list test to pass when running in headless browser mode so that I can clear the options in the select_list using s.clear ?
  2. Is there any other workarounds ?

In regards to 2) I'm experimenting with trying to send CONTROL and mouse click select commands using the actionbuilder class in selenium webdriver to simulate clearing the selected options as a user would do through the UI.

Please note the below code I use that launches the browser in headless mode:

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 
1
If you create a page with just a multi-select list, does s.multiple? still always return false for you? I tried reproducing your issue (using the HtmlUnitDriver), but s.multiple? returned true as expected.Justin Ko
@JustinKo thanks for your suggestion. I tried it and s.multiple? always returns falseCosta
What version of Selenium-WebDriver and Watir-WebDriver are you using? I noticed that your code shows the usage of "selenium-server-standalone-2.0b1.jar", which is 4 years old?Justin Ko
My development environment is: Windows 2003 Server, IE8 (local browser), Ruby 1.9.3 -p194, selenium-webdriver v2.26.0 and watir-webdriver v0.6.1. Should I be updating any of these? When you tried to reproduce what was your environment setup?Costa
Forgot to add that I am using the "selenium-server-standalone-2.0b1.jar"Costa

1 Answers

0
votes

Thanks to @JustinKo upgraded the selenium-server-standalone-2.0b1.jar to the latest version selenium-server-standalone-2.44.0.jar and now getting the right output as below without exception being raised.

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