watirloo 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +22 -0
  2. data/History.txt +44 -0
  3. data/Manifest.txt +59 -0
  4. data/README.rdoc +94 -0
  5. data/Rakefile +68 -0
  6. data/VERSION +1 -0
  7. data/lib/watirloo/browsers.rb +73 -0
  8. data/lib/watirloo/desktop.rb +44 -0
  9. data/lib/watirloo/extension/firewatir_ducktape.rb +194 -0
  10. data/lib/watirloo/extension/object.rb +32 -0
  11. data/lib/watirloo/extension/watir_ducktape.rb +552 -0
  12. data/lib/watirloo/extension/watir_reflector.rb +83 -0
  13. data/lib/watirloo/locker.rb +85 -0
  14. data/lib/watirloo/page.rb +140 -0
  15. data/lib/watirloo.rb +16 -0
  16. data/spec/browser_spec.rb +38 -0
  17. data/spec/browser_threads_spec.rb +45 -0
  18. data/spec/checkbox_group_spec.rb +136 -0
  19. data/spec/checkbox_groups_spec.rb +55 -0
  20. data/spec/checkboxes_value_spec.rb +35 -0
  21. data/spec/desktop_spec.rb +54 -0
  22. data/spec/extra/browser_events_spec.rb +76 -0
  23. data/spec/extra/page_objects_metrics.rb +139 -0
  24. data/spec/face_mixing_spec.rb +55 -0
  25. data/spec/firewatir/attach_instance_test.rb +38 -0
  26. data/spec/firewatir/spec_results.html +263 -0
  27. data/spec/firewatir/spec_results.txt +23 -0
  28. data/spec/firewatir/spec_results_failed.txt +3 -0
  29. data/spec/html/census.html +332 -0
  30. data/spec/html/checkbox_group1.html +33 -0
  31. data/spec/html/frameset1.html +17 -0
  32. data/spec/html/labels.html +53 -0
  33. data/spec/html/no_title.html +13 -0
  34. data/spec/html/person.html +37 -0
  35. data/spec/html/radio_group.html +35 -0
  36. data/spec/html/select_lists.html +82 -0
  37. data/spec/input_element_spec.rb +51 -0
  38. data/spec/label_spec.rb +65 -0
  39. data/spec/locker_spec.rb +49 -0
  40. data/spec/page_spec.rb +91 -0
  41. data/spec/person_def_wrappers_spec.rb +40 -0
  42. data/spec/radio_group_spec.rb +95 -0
  43. data/spec/radio_groups_spec.rb +55 -0
  44. data/spec/reflector_spec.rb +82 -0
  45. data/spec/select_list_options_spec.rb +40 -0
  46. data/spec/select_lists_spec.rb +151 -0
  47. data/spec/spec_helper.rb +20 -0
  48. data/spec/spec_helper_ff.rb +5 -0
  49. data/spec/spec_helper_runner.rb +13 -0
  50. data/spec/spec_results.html +556 -0
  51. data/spec/spec_results.txt +175 -0
  52. data/spec/spec_results_failed.txt +1 -0
  53. data/spec/text_fields_spec.rb +56 -0
  54. data/watirloo.gemspec +122 -0
  55. metadata +150 -0
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ describe 'text field wrapped in label tag without for attribute defined' do
5
+
6
+ include Watirloo::Page
7
+ face(:first) { text_field(:name, 'fn') }
8
+ face(:last) { text_field(:name, 'ln') }
9
+
10
+ before do
11
+ browser.goto testfile('labels.html')
12
+ end
13
+
14
+ it 'parent of text_field should be Watir Element' do
15
+ if browser.kind_of?(FireWatir::Firefox)
16
+ first.parent.should be_kind_of(String)
17
+ last.parent.should be_kind_of?(String)
18
+ flunk('FIXME Firefox returns String for parent and not Element')
19
+
20
+ elsif browser.kind_of?(Watir::IE)
21
+ first.parent.should be_kind_of(Watir::Element)
22
+ last.parent.should be_kind_of(Watir::Element)
23
+ end
24
+
25
+ end
26
+
27
+ it 'parent tagName should be a LABEL' do
28
+ if browser.kind_of?(Watir::IE)
29
+ first.parent.document.tagName.should == "LABEL"
30
+ last.parent.document.tagName.should == "LABEL"
31
+
32
+ elsif browser.kind_of?(FireWatir::Firefox)
33
+ flunk('FIXME Firefox returns String for parent and not Element')
34
+ end
35
+ end
36
+
37
+ it 'parent text returns text of label' do
38
+ if browser.kind_of?(Watir::IE)
39
+ first.parent.text.should == 'First Name'
40
+ last.parent.text.should == 'Last Name'
41
+
42
+ elsif browser.kind_of?(FireWatir::Firefox)
43
+ flunk('FIXME Firefox returns String for parent and not Element.')
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+
50
+ describe 'label for text field not wrapped' do
51
+
52
+ # reopen the class and add more interfaces
53
+ include Watirloo::Page
54
+ face(:first_label) { label(:for, 'first_nm') }
55
+ face(:last_label) { label(:for, 'last_nm') }
56
+
57
+ before do
58
+ browser.goto testfile('labels.html')
59
+ end
60
+
61
+ it 'text value of label' do
62
+ first_label.text.should == 'FirstName For'
63
+ last_label.text.should == 'LastName For'
64
+ end
65
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ describe "Locker" do
5
+
6
+ it "locker file does not exist. create it. mapping should return empty hash" do
7
+ Watirloo::Locker.mapping.clear
8
+ FileUtils.rm_f(Watirloo::Locker.locker) if FileTest.exist?(Watirloo::Locker.locker) #remove locker file
9
+ FileTest.exist?(Watirloo::Locker.locker).should be_false
10
+ Watirloo::Locker.mapping.should == {}
11
+ end
12
+
13
+ it "clear should create locker file and save empty mapping" do
14
+ Watirloo::Locker.clear
15
+ FileTest.exist?(Watirloo::Locker.locker).should be_true
16
+ Watirloo::Locker.mapping.should == {}
17
+ end
18
+
19
+ it 'add stores ie.hwnd with friendly name and adds it to mapping' do
20
+ ie = Watir::IE.new
21
+ Watirloo::Locker.add(ie, 'one')
22
+ Watirloo::Locker.add(ie, 'two')
23
+ end
24
+
25
+ it 'mapping holds what was added' do
26
+ Watirloo::Locker.mapping.keys.sort.should == ['one', 'two']
27
+ Watirloo::Locker.mapping['one'].should == Watirloo::Locker.mapping['two']
28
+ end
29
+
30
+ it 'remove deletes a key value record ' do
31
+ Watirloo::Locker.remove 'two'
32
+ Watirloo::Locker.mapping.keys.should_not include('two')
33
+ end
34
+
35
+ it 'browser reattaches to named browser based on windows handle' do
36
+ ie = Watirloo::Locker.browser 'one'
37
+ ie.should be_kind_of(Watir::IE)
38
+ ie.hwnd.should == Watirloo::Locker.mapping['one']
39
+ ie.should exist
40
+ ie.close
41
+ ie.should_not exist
42
+ end
43
+
44
+ it 'browser attach to nonexisting windows behaves like IE.attach, it raises error' do
45
+ sleep 6 # if previous test closes a browser we need to wait to ensure we don't reattach to a closing browser
46
+ (lambda {Watirloo::Locker.browser('one')}).should raise_error(Watir::Exception::NoMatchingWindowFoundException) #points to the same hwnd as 'one' but at this time does not exist any more
47
+ end
48
+
49
+ end
data/spec/page_spec.rb ADDED
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Page class with face definitions" do
4
+ class Page1
5
+ include Watirloo::Page
6
+ end
7
+
8
+ it 'has face method as singleton' do
9
+ Page1.singleton_methods.should include('face')
10
+ end
11
+
12
+ it 'face class method defines method' do
13
+ Page1.face(:bla) do
14
+ "hello"
15
+ end
16
+ page = Page1.new
17
+ page.should respond_to(:bla)
18
+ page.bla.should == 'hello'
19
+ end
20
+
21
+ it 'face accepts args used by method body' do
22
+ Page1.face(:foo) do |x|
23
+ x * 2
24
+ end
25
+ page = Page1.new
26
+ page.foo(2).should == 4
27
+ page.foo("bla").should == "blabla"
28
+ end
29
+
30
+ it "when optional args not supplied provide default arg in method" do
31
+ # this is a strange design decision. I want to provide method arg with default
32
+ # example def bar(x=0)
33
+ Page1.face(:bar) do |*x|
34
+ x = x[0] || 0
35
+ x
36
+ end
37
+ page = Page1.new
38
+ page.bar.should == 0
39
+ page.bar(3).should == 3
40
+ end
41
+ end
42
+
43
+ describe "Page faces included in rspec" do
44
+
45
+ include Watirloo::Page
46
+ face(:last1) { text_field(:name, 'last_name0')}
47
+ face(:last) {|nbr| text_field(:name, "last_name#{nbr+1}")}
48
+
49
+ before do
50
+ browser.goto testfile('census.html')
51
+ end
52
+
53
+
54
+ it 'face defines a watir element access' do
55
+ last1.set "Zippididuda"
56
+ last1.value.should == 'Zippididuda'
57
+ end
58
+
59
+ it 'faces with arguments' do
60
+ last(1).set "Zorro"
61
+ last(1).value.should == "Zorro"
62
+ end
63
+
64
+
65
+ end
66
+
67
+
68
+ describe "Page doc provides access to frame in frameset browser" do
69
+
70
+ include Watirloo::Page
71
+ face(:last1) {text_field(:name, 'last_name0')}
72
+ face(:last) {|nbr| text_field(:name, "last_name#{nbr+1}")}
73
+
74
+ before do
75
+ browser.goto testfile('frameset1.html')
76
+ self.page = browser.frame(:name,'census_frame')
77
+ end
78
+
79
+
80
+ it 'face defines a watir element access' do
81
+ last1.set "Zippididuda"
82
+ last1.value.should == 'Zippididuda'
83
+ end
84
+
85
+ it 'faces with arguments' do
86
+ last(1).set "Zorro"
87
+ last(1).value.should == "Zorro"
88
+ end
89
+
90
+
91
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Person Page interfaces defined by def wrappers and class definitions" do
4
+
5
+ include Watirloo::Page
6
+ # declare accessing elements
7
+ face(:first) { text_field(:name, 'first_nm') }
8
+ face(:street) { text_field(:name, 'addr1') }
9
+
10
+ # def wrapper helper with suggested semantic name returns dom element
11
+ def last
12
+ browser.text_field(:name, 'last_nm')
13
+ end
14
+
15
+ def dob
16
+ browser.text_field(:name, 'dob')
17
+ end
18
+
19
+ before :each do
20
+ browser.goto testfile('person.html')
21
+ end
22
+
23
+ it 'calling face when there is wrapper method' do
24
+ last.set 'Wonkatonka'
25
+ last.value.should == 'Wonkatonka'
26
+ end
27
+
28
+ it 'calling interface when there is definition and no method' do
29
+ first.set 'Oompaloompa'
30
+ first.value.should == 'Oompaloompa'
31
+ end
32
+
33
+ it 'spray method by convetion has keys correspondig to interface names for watir elements' do
34
+ datamap = {:street => '13 Sad Enchiladas Lane', :dob => '02/03/1977'}
35
+ spray datamap
36
+ street.value.should == datamap[:street]
37
+ dob.value.should == datamap[:dob]
38
+ end
39
+
40
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'RadioGroup class access in watir browser' do
4
+ include Watirloo::Page
5
+
6
+ before :each do
7
+ browser.goto testfile('radio_group.html')
8
+ end
9
+
10
+ it 'browser responds to radio_group' do
11
+ browser.should respond_to(:radio_group)
12
+ end
13
+
14
+ it 'radio group needs :what value with implicit :how=name' do
15
+ rg = browser.radio_group('food')
16
+ rg.size.should == 3
17
+ rg.values.should == %w[hotdog burger tofu]
18
+ end
19
+ end
20
+
21
+
22
+ describe 'RadioGroup class interface in watirloo' do
23
+
24
+ include Watirloo::Page
25
+ face :meals_to_go do
26
+ radio_group('food')
27
+ end
28
+
29
+ before do
30
+ browser.goto testfile('radio_group.html')
31
+ end
32
+
33
+ it 'container radio_group method returns RadioGroup class' do
34
+ # verify browser namespace explicitly
35
+ if browser.kind_of?(FireWatir::Firefox)
36
+ meals_to_go.should be_kind_of(FireWatir::RadioGroup)
37
+ elsif browser.kind_of?(Watir::IE)
38
+ meals_to_go.should be_kind_of(Watir::RadioGroup)
39
+ end
40
+ end
41
+
42
+ it 'size or count returns how many radios in a group' do
43
+ meals_to_go.size.should == 3
44
+ meals_to_go.count.should == 3
45
+ end
46
+
47
+ it 'values returns value attributes text items as an array' do
48
+ meals_to_go.values.should == ["hotdog", "burger", "tofu"]
49
+ end
50
+
51
+ it 'selected_value returns internal option value for selected radio item in a group' do
52
+ meals_to_go.selected.should == 'burger'
53
+ meals_to_go.selected_value.should == 'burger'
54
+ meals_to_go.selected_values.should == ['burger'] # matches select_list api
55
+ end
56
+
57
+ it 'set selects radio by position in a group' do
58
+ meals_to_go.set 3
59
+ meals_to_go.selected.should == 'tofu'
60
+ meals_to_go.selected_value.should == 'tofu'
61
+ meals_to_go.selected_values.should == ['tofu']
62
+ meals_to_go.selected.should_not == 'hotdog'
63
+
64
+ meals_to_go.set 1
65
+ meals_to_go.selected.should == 'hotdog'
66
+ meals_to_go.selected_value.should == 'hotdog'
67
+ meals_to_go.selected_values.should == ['hotdog']
68
+ meals_to_go.selected.should_not == 'tofu'
69
+ end
70
+
71
+ it 'set selects radio by value in a group. selected returns value' do
72
+ meals_to_go.set 'hotdog'
73
+ meals_to_go.selected.should == 'hotdog'
74
+ meals_to_go.selected.should_not == 'tofu'
75
+
76
+ meals_to_go.set 'tofu'
77
+ meals_to_go.selected_value.should == 'tofu'
78
+ meals_to_go.selected.should_not == 'hotdog'
79
+ end
80
+
81
+ it 'set position throws exception if number not within the range of group size' do
82
+ lambda{ meals_to_go.set 7 }.should raise_error(Watir::Exception::WatirException)
83
+ end
84
+
85
+ it 'set value throws exception if value not found in options' do
86
+ lambda{ meals_to_go.set 'banannnanna' }.should raise_error(Watir::Exception::WatirException)
87
+ end
88
+
89
+ # TODO do I want to provide mapping of human generated semantic values for radios
90
+ # to actual values here in the radio_group or at the Watirllo level only?
91
+ it 'set throws exception if sybmol is used. it should accept Fixnum or String element only' do
92
+ lambda{ meals_to_go.set :yes }.should raise_error(Watir::Exception::WatirException)
93
+ end
94
+
95
+ end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'RadioGroup class access in watir browser' do
4
+ include Watirloo::Page
5
+
6
+ before :each do
7
+ browser.goto testfile('radio_group.html')
8
+ end
9
+
10
+ it 'browser responds to radio_group' do
11
+ browser.should respond_to(:radio_groups)
12
+ end
13
+
14
+ it 'returns RadioGroups class' do
15
+ browser.radio_groups.should be_kind_of(Watir::RadioGroups)
16
+ end
17
+
18
+ it 'lenght returns integer count of groups' do
19
+ browser.radio_groups.length.should == 2
20
+ end
21
+
22
+ it 'each iterator returns RadioGroup' do
23
+ browser.radio_groups.each do |rg|
24
+ rg.class.should == Watir::RadioGroup #single
25
+ end
26
+ end
27
+
28
+ it 'each accesses the group and returns name' do
29
+ names =[]
30
+ browser.radio_groups.each do |rg|
31
+ names << rg.name
32
+ end
33
+ names.should == ['food', 'fooda']
34
+ end
35
+
36
+ it 'bracket access[] returns 1-based indexed group' do
37
+ browser.radio_groups[1].class.should == Watir::RadioGroup
38
+ browser.radio_groups[1].values.should == ["hotdog", "burger", "tofu"]
39
+ browser.radio_groups[2].name.should == 'fooda'
40
+ end
41
+
42
+ it 'if radio group does not exists it returns size 0 or name nil (or should it blow up? or respond to exists? method' do
43
+ browser.radio_groups[6].size.should == 0 # does not exist. let's not blow up. suggestions?
44
+ browser.radio_groups[6].name.should == nil #suggestions?
45
+ end
46
+
47
+ it 'groups contained by a form element' do
48
+ browser.forms[1].radio_groups.length.should == 1
49
+ names =[]
50
+ browser.forms[1].radio_groups.each do |rg|
51
+ names << rg.name
52
+ end
53
+ names.should == ['food']
54
+ end
55
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ #each collection can reflect the accessors and specs for its own members
5
+ describe 'reflext :text_fields' do
6
+
7
+ include Watirloo::Page
8
+
9
+ before do
10
+ browser.goto testfile('person.html')
11
+ end
12
+
13
+ it 'text_fields.reflect each :text_field' do
14
+ expected = ["face(:last_nm) {text_field(:name, \"last_nm\")}",
15
+ "last_nm.value.should == \"Begoodnuffski\"",
16
+ "face(:first_nm) {text_field(:name, \"first_nm\")}",
17
+ "first_nm.value.should == \"Joanney\"",
18
+ "face(:dob) {text_field(:name, \"dob\")}",
19
+ "dob.value.should == \"05/09/1964\"",
20
+ "face(:addr1) {text_field(:name, \"addr1\")}",
21
+ "addr1.value.should == \"1600 Transylavnia Ave.\""]
22
+
23
+ browser.text_fields.reflect.should == expected
24
+ end
25
+ end
26
+
27
+
28
+
29
+ describe 'reflect :radio_groups' do
30
+
31
+ include Watirloo::Page
32
+
33
+ before do
34
+ browser.goto testfile('radio_group.html')
35
+ end
36
+
37
+ it 'reflects each radio group' do
38
+
39
+ expected = ["face(:food) {radio_group(\"food\")}",
40
+ "food.values.should == [\"hotdog\", \"burger\", \"tofu\"]",
41
+ "food.selected.should == \"burger\"",
42
+ "face(:fooda) {radio_group(\"fooda\")}",
43
+ "fooda.values.should == [\"hotdoga\", \"burgera\", \"tofua\", \"hotdoga_t\", \"burgera_t\", \"tofua_t\"]",
44
+ "fooda.selected.should == \"tofua\""]
45
+
46
+ # here the radio_group pics up the same named elemnets in two distinct form containers
47
+ # this would be a bug if container is browser
48
+ browser.radio_groups.reflect.should == expected
49
+
50
+ end
51
+ end
52
+
53
+
54
+
55
+
56
+ describe 'reflect :checkbox_groups' do
57
+
58
+ include Watirloo::Page
59
+
60
+ before do
61
+ browser.goto testfile('checkbox_group1.html')
62
+ end
63
+
64
+ it 'reflects each checkbox_group' do
65
+
66
+ expected = ["face(:pets) {checkbox_group(\"pets\")}",
67
+ "pets.values.should == [\"cat\", \"dog\", \"zook\", \"zebra\", \"wumpa\"]",
68
+ "pets.selected.should == nil",
69
+ "face(:single_indicator) {checkbox_group(\"singleIndicator\")}",
70
+ "single_indicator.values.should == [\"on\"]",
71
+ "single_indicator.selected.should == nil",
72
+ "face(:petsa) {checkbox_group(\"petsa\")}",
73
+ "petsa.values.should == [\"cata\", \"doga\", \"zooka\", \"zebraa\", \"wumpaa\"]",
74
+ "petsa.selected.should == nil",
75
+ "face(:single_indicatora) {checkbox_group(\"singleIndicatora\")}",
76
+ "single_indicatora.values.should == [\"on\"]",
77
+ "single_indicatora.selected.should == nil"]
78
+
79
+ browser.checkbox_groups.reflect.should == expected
80
+ end
81
+
82
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "SelectList options as visible items and values as hidden to the user attributes" do
4
+
5
+ include Watirloo::Page
6
+
7
+ face(:pets) { select_list(:name, 'animals') }
8
+ face(:gender) { select_list(:name, 'sex_cd') }
9
+ face(:toys) { select_list(:name, 'bubel') }
10
+
11
+ before :each do
12
+ browser.goto testfile('select_lists.html')
13
+ end
14
+
15
+ it 'values of options by facename method' do
16
+ gender.values.should == ['', 'm', 'f']
17
+ pets.values.should == ['o1', 'o2', 'o3', 'o4', 'o5']
18
+ end
19
+
20
+ it 'options with no value attribute' do
21
+ # in case of IE it will return all blanks
22
+ if browser.kind_of?(Watir::IE)
23
+ toys.values.should == ["", "", "", "", ""]
24
+ elsif browser.kind_of?(FireWatir::Firefox)
25
+ toys.values.should == ["", "foobel", "barbel", "bazbel", "chuchu"]
26
+ # for Firfox it returns actual items
27
+ end
28
+ end
29
+
30
+ it 'items method returns visible contents as array of text items' do
31
+ toys.items.should == ["", "foobel", "barbel", "bazbel", "chuchu"]
32
+ end
33
+
34
+ it 'items returns visible text items as array' do
35
+ pets.items.should == ['cat', 'dog', 'zook', 'zebra', 'wumpa']
36
+ gender.items.should == ["", "M", "F"]
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,151 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ # testing single select and multiselect controls
5
+ describe "SelectList selections" do
6
+
7
+ include Watirloo::Page
8
+
9
+ face(:pets) {select_list(:name, 'animals')}
10
+ face(:gender) {select_list(:name, 'sex_cd')}
11
+
12
+
13
+ before do
14
+ browser.goto testfile('select_lists.html')
15
+ end
16
+
17
+ it 'selected returns preselected item in single select' do
18
+ gender.selected.should == '' # in single select "" is preselected
19
+ gender.selected_item.should == '' # in single select "" is preselected
20
+ gender.selected_items.should == ['']
21
+ end
22
+
23
+ it 'selected returns preselected value in single select' do
24
+ gender.selected_value.should == '' # in single select "" is preselected
25
+ gender.selected_values.should == ['']
26
+ end
27
+
28
+
29
+ it 'selected returns nil for none selected items in multi select' do
30
+ pets.selected.should == nil # in multiselect noting is selected
31
+ pets.selected_item.should == nil
32
+ pets.selected_items.should == [] # as array
33
+ end
34
+
35
+ it 'selected returns nil for none selected values in multi select' do
36
+ pets.selected_value.should == nil
37
+ pets.selected_values.should == [] # as array
38
+ end
39
+
40
+ it 'set item text and find selected item and text for multiselect' do
41
+ pets.set 'dog'
42
+ pets.selected.should == 'dog' #multi select one item selected
43
+ pets.selected_item.should == 'dog' #multi select one item selected
44
+ pets.selected_items.should == ['dog']
45
+ end
46
+
47
+ it 'set value and find selected item and value for multiselect' do
48
+ pets.set_value 'o2'
49
+ pets.selected.should == 'dog' #multi select one item selected
50
+ pets.selected_value.should == 'o2' #multi select one item selected
51
+ pets.selected_values.should == ['o2']
52
+ end
53
+
54
+ it 'set and query option by text for single select' do
55
+ gender.set 'F'
56
+ gender.selected.should == 'F' # single select one item
57
+ gender.selected_item.should == 'F' # single select one item
58
+ gender.selected_items.should == ['F'] # single select one item
59
+ end
60
+
61
+ it 'set and query option by value for single select' do
62
+ gender.set_value 'f'
63
+ gender.selected.should == 'F'
64
+ gender.selected_value.should == 'f' # single select one item
65
+ gender.selected_values.should == ['f'] # single select one item
66
+ end
67
+
68
+
69
+ it 'set by text multple items for multiselect selects each item' do
70
+ pets.set ['cat', 'dog']
71
+ pets.selected.should == ['cat','dog']
72
+ pets.selected_item.should == ['cat','dog'] # bypass filter when more than one item
73
+ pets.selected_items.should == ['cat','dog']
74
+ end
75
+
76
+ it 'set by value multple items for multiselect selects each item' do
77
+ pets.set_value ['o1', 'o2']
78
+ pets.selected.should == ['cat','dog']
79
+ pets.selected_value.should == ['o1','o2'] # bypass filter when more than one item
80
+ pets.selected_value.should == ['o1','o2']
81
+ end
82
+
83
+ # this is not practical for single select but can be done for testing
84
+ # conditions arising from switching items in a batch approach
85
+ it 'set items array for single select selects each in turn. selected is the last item in array' do
86
+ gender.set ['M', 'F', '','F']
87
+ gender.selected.should == 'F'
88
+ end
89
+
90
+ it 'set item after multiple items were set returns all values selected for multiselect' do
91
+ pets.set ['cat','zook']
92
+ pets.set 'zebra'
93
+ pets.selected.should == ['cat', 'zook', 'zebra']
94
+ pets.selected_values.should == ['o1', 'o3', 'o4']
95
+ end
96
+
97
+ it 'set using position for multiselect' do
98
+ pets.set 3
99
+ pets.selected.should == 'zook'
100
+ pets.set_value 2 # translate to second text item
101
+ pets.selected.should == ['dog', 'zook']
102
+ pets.set [1,4,5]
103
+ pets.selected.should == ['cat','dog','zook', 'zebra','wumpa']
104
+ end
105
+
106
+ it 'set using position and item for multiselect' do
107
+ pets.set [1,'zebra', 'zook', 2, 4] #select already selected
108
+ pets.selected.should == ['cat','dog','zook','zebra']
109
+ end
110
+
111
+ it 'set using position for single select' do
112
+ gender.set 2
113
+ gender.selected.should == 'M'
114
+ gender.selected_value.should == 'm'
115
+ end
116
+
117
+ it 'clear removes selected attribute for all selected items in multiselect' do
118
+ pets.selected.should == nil
119
+ pets.set ['zook', 'cat']
120
+ pets.selected.should == ['cat','zook']
121
+ pets.clear
122
+ pets.selected.should == nil
123
+ end
124
+
125
+ it 'clear removes selected attribute for item in single select list' do
126
+ gender.selected.should == ''
127
+ gender.set 'F'
128
+ gender.selected.should == 'F'
129
+
130
+ # This fails on IE in single select list.
131
+ # The test passes in Firefox
132
+ # option item select = false does not set false like it does in multiselect
133
+ gender.clear
134
+ gender.selected.should_not == 'F'
135
+ end
136
+
137
+ it 'set_value selects value atribute text' do
138
+ gender.set_value 'm'
139
+ gender.selected.should == 'M'
140
+ gender.selected_value.should == 'm' #when you know there is only one item expected
141
+ gender.selected_values.should == ['m'] # array of items
142
+ end
143
+
144
+ it 'set_value for multiselect returns selected and selected_values' do
145
+ pets.set_value 'o2'
146
+ pets.set_value 'o4'
147
+ pets.selected.should == ['dog', 'zebra']
148
+ pets.selected_value.should == ['o2', 'o4'] # if array then bypass filter
149
+ pets.selected_values.should == ['o2', 'o4'] # plural
150
+ end
151
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'watirloo'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
10
+
11
+ module WatirlooSpecHelper
12
+ def testfile(filename)
13
+ path = File.expand_path(File.dirname(__FILE__))
14
+ uri = "file://#{path}/html/" + filename
15
+ return uri
16
+ end
17
+ end
18
+
19
+ include WatirlooSpecHelper
20
+