marekj-watirloo 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/History.txt +12 -0
  2. data/Manifest.txt +59 -34
  3. data/README.rdoc +63 -80
  4. data/Rakefile.rb +32 -39
  5. data/config/locker.yml +0 -0
  6. data/lib/watirloo.rb +9 -162
  7. data/lib/watirloo/browsers.rb +73 -0
  8. data/lib/watirloo/desktop.rb +44 -0
  9. data/lib/watirloo/{firewatir_ducktape.rb → extension/firewatir_ducktape.rb} +0 -0
  10. data/lib/watirloo/extension/object.rb +26 -0
  11. data/lib/watirloo/{watir_ducktape.rb → extension/watir_ducktape.rb} +181 -16
  12. data/lib/watirloo/extension/watir_reflector.rb +83 -0
  13. data/lib/watirloo/locker.rb +84 -0
  14. data/lib/watirloo/page.rb +105 -0
  15. data/spec/browser_spec.rb +38 -0
  16. data/spec/browser_threads_spec.rb +45 -0
  17. data/spec/checkbox_group_spec.rb +136 -0
  18. data/spec/checkbox_groups_spec.rb +55 -0
  19. data/spec/checkboxes_value_spec.rb +35 -0
  20. data/spec/desktop_spec.rb +54 -0
  21. data/spec/extra/browser_events_spec.rb +76 -0
  22. data/spec/extra/page_objects_metrics.rb +139 -0
  23. data/spec/face_mixing_spec.rb +55 -0
  24. data/{test → spec}/firewatir/attach_instance_test.rb +0 -0
  25. data/spec/firewatir/spec_results.html +263 -0
  26. data/spec/firewatir/spec_results.txt +23 -0
  27. data/spec/firewatir/spec_results_failed.txt +3 -0
  28. data/{test → spec}/html/census.html +0 -0
  29. data/spec/html/checkbox_group1.html +33 -0
  30. data/spec/html/labels.html +53 -0
  31. data/spec/html/no_title.html +13 -0
  32. data/{test → spec}/html/person.html +0 -0
  33. data/spec/html/radio_group.html +35 -0
  34. data/{test → spec}/html/select_lists.html +0 -0
  35. data/spec/input_element_spec.rb +51 -0
  36. data/spec/label_spec.rb +65 -0
  37. data/spec/locker_spec.rb +49 -0
  38. data/spec/page_spec.rb +53 -0
  39. data/spec/person_def_wrappers_spec.rb +40 -0
  40. data/spec/radio_group_spec.rb +95 -0
  41. data/spec/radio_groups_spec.rb +55 -0
  42. data/spec/reflector_spec.rb +82 -0
  43. data/spec/select_list_options_spec.rb +40 -0
  44. data/spec/select_lists_spec.rb +151 -0
  45. data/{test/test_helper.rb → spec/spec_helper.rb} +6 -4
  46. data/spec/spec_helper_ff.rb +5 -0
  47. data/spec/spec_helper_runner.rb +13 -0
  48. data/spec/spec_results.html +566 -0
  49. data/spec/spec_results.txt +179 -0
  50. data/spec/spec_results_failed.txt +1 -0
  51. data/spec/text_fields_spec.rb +56 -0
  52. data/watirloo.gemspec +44 -44
  53. metadata +80 -39
  54. data/lib/watirloo/reflector.rb +0 -137
  55. data/test/checkbox_group_test.rb +0 -83
  56. data/test/checkboxes_value_test.rb +0 -50
  57. data/test/html/checkbox_group1.html +0 -20
  58. data/test/html/labels.html +0 -32
  59. data/test/html/radio_group.html +0 -41
  60. data/test/interfaces_test.rb +0 -79
  61. data/test/label_test.rb +0 -64
  62. data/test/person_def_wrappers_test.rb +0 -55
  63. data/test/radio_group_test.rb +0 -97
  64. data/test/select_list_in_class_test.rb +0 -39
  65. data/test/select_list_options_test.rb +0 -39
  66. data/test/select_lists_test.rb +0 -145
  67. data/test/text_fields_test.rb +0 -68
@@ -1,137 +0,0 @@
1
- =begin rdoc
2
- Look Ma!, I can Has Reflect The Browser
3
-
4
- Watir::Reflector module added to watir.
5
- Run the script to reflect watir elements. reflections create wrapper methods
6
- with suggested semantic naming based on id, name, value or combination.
7
- the intention is to create a scaffolding for Watirloo::Page elements.
8
- author: marekj
9
- works with IE class and DOM elements.
10
- =end
11
- module Watir
12
-
13
- # Watirloo::Page objects scaffold creation. Talks to the current page and reflects
14
- # the watir elements to be used for semantic test objects tests.
15
- module Reflector
16
-
17
- @@reflectable_list = [
18
- :text_fields,
19
- :radios,
20
- :checkboxes,
21
- :select_lists
22
- ]
23
-
24
- #cleanup the def name for some kind of semantic name
25
- def suggest_def_name(how)
26
- how.gsub!(/_+/,'_') # double underscores to one
27
- how.gsub!(/^_/, '') # if it begins with undrscore kill it.
28
- how.gsub!(/\s+/, '_') # kill spaces if for some strange reason exist
29
- how = how[0,1].downcase << how[1,how.size] #downcase firs char
30
- end
31
-
32
- # glean(:text_fields, [:id, :name, :value]
33
- # glean(:radios, [:id, :name, :value])
34
- # glean and make a map of types and attributes needed for reflection
35
- # this should be private I think
36
- def glean(types, attribs)
37
- result = []
38
- send(types).each do |el|
39
- subresult = {}
40
- attribs.each do |key|
41
- v = el.attribute_value key.to_s
42
- subresult.update key => v
43
- end
44
- result << subresult
45
- end
46
- return result
47
- end
48
-
49
- # example make_reflection(:checkboxes) # => [ defs, setters, faces]
50
- # returns array of def wrappers, setters for elements and face definitions configs.
51
- def make_reflection(types)
52
- attribs = [:id, :name, :value]
53
- faces = glean(types, attribs)
54
- watir_method = types.id2name.chop
55
- if watir_method == 'checkboxe'
56
- watir_method = 'checkbox' #ooopps ... irregular plural
57
- end
58
- def_results = "# #{types.id2name.upcase}: def wrappers with suggested semantic names for elements\n" #holds definition wrappers
59
- set_results = "# #{types.id2name.upcase}: setters calling def wrappers with captured values\n" #holds setters with gleaned values
60
- face_results = "# #{types.id2name.upcase}: face definitions\n" #holds faces
61
-
62
- faces.each do |face|
63
- id, name, value = face[:id], face[:name], face[:value]
64
-
65
- if id != ''
66
- how, how_s = id, :id
67
- elsif name != ''
68
- how, how_s = name, :name
69
- elsif value != ''
70
- how, how_s = value, :value
71
- end
72
-
73
- def_name = suggest_def_name(how)
74
-
75
- case types
76
- when :checkboxes, :radios
77
- extra_value = ", '#{value}'" #for checkboxes and radios
78
- def_value = "_#{value}" #for checkboxes and radios
79
- def_results << "\ndef #{def_name}#{def_value}\n\s\s@b.#{watir_method}(:#{how_s}, '#{how}'#{extra_value})\nend\n"
80
- set_results << "#{def_name}#{def_value}.set\n"
81
- face_results << ":#{def_name}#{def_value} => [:#{watir_method}, :#{how_s}, '#{how}'#{extra_value}]\n"
82
-
83
- when :select_lists
84
- # round trip back to browser for items and contents
85
- value = eval("select_list(:#{how_s}, '#{how}').getSelectedItems")
86
- items = eval("select_list(:#{how_s}, '#{how}').getAllContents")
87
-
88
- def_results << "def #{def_name}\n\s\s@b.select_list(:#{how_s}, '#{how}')\nend\n"
89
- set_results << "@@#{def_name}_items=#{items.inspect}\n" #class vars for values collections
90
- set_results << "#{def_name}.set #{value.inspect}\n"
91
- face_results << "#:#{def_name} => [:select_list, :#{how_s}, '#{name}}']\n"
92
-
93
- else
94
- def_results << "\ndef #{def_name}#{def_value}\n\s\s@b.#{watir_method}(:#{how_s}, '#{how}'#{extra_value})\nend\n"
95
- set_results << "#{def_name}#{def_value}.set\n"
96
- face_results << "\n#:#{def_name}#{def_value} = [:#{watir_method}, :#{how_s}, '#{how}#{extra_value}']\n"
97
-
98
- end
99
-
100
- end
101
-
102
- return [def_results, set_results, face_results]
103
- end
104
- private :suggest_def_name, :glean, :make_reflection
105
-
106
- # public interface for Reflector.
107
- # ie.reflect(:all) # => returns object definitions for entire dom using ie as container
108
- # ie.frame('main').reflect(:select_lists) # => returns definitions for select_lists only contained by the frame
109
- # ie.div(:id, 'main').div(:id, 'content').reflect(:all) # => definitions for all supported elements contained by a div 'content' inside div 'main'
110
- # you can be as granular as needed
111
- def reflect(watir_types=:all)
112
- results = []
113
- case watir_types
114
- when :all
115
- @@reflectable_list.each do |types|
116
- results << make_reflection(types)
117
- end
118
- else
119
- unless @@reflectable_list.include?(watir_types)
120
- raise ArgumentError, "reflect method does not respond to this argument: #{watir_method}"
121
- end
122
- results << make_reflection(watir_types)
123
- end
124
- return results
125
- end
126
- end
127
-
128
- # ducktape IE container and include the Reflector.
129
- class IE
130
- include Reflector
131
- end
132
-
133
- module Container
134
- include Reflector
135
- end
136
-
137
- end
@@ -1,83 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- describe 'checkbox_group access for browser' do
4
- before :each do
5
- page = Watirloo::Page.new
6
- @browser = page.browser
7
- @browser.goto testfile('checkbox_group1.html')
8
- end
9
-
10
- it 'browser responds to checkbox_group' do
11
- @browser.respond_to?(:checkbox_group).should == true
12
- end
13
-
14
- it 'returns group object and its values from the page' do
15
- cbg = @browser.checkbox_group('pets')
16
- cbg.size.should == 5
17
- cbg.values.should == %w[cat dog zook zebra wumpa]
18
- end
19
- end
20
-
21
- describe 'CheckboxGroup class access with page interface' do
22
-
23
- class CheckboxGroupPage < Watirloo::Page
24
- # semantic wrapper for the radio group object
25
- face :pets => [:checkbox_group, 'pets']
26
- end
27
-
28
- before do
29
- @page = CheckboxGroupPage.new
30
- @page.b.goto testfile('checkbox_group1.html')
31
- end
32
-
33
- # let's check explicitly for test purpose what Class is we are dealing with
34
- # if IE then Watir::CheckboxGroup
35
- # if FF then FireWatir::CheckboxGroup
36
- it 'checkbox_group container method returns CheckboxGroup class' do
37
- if @page.b.kind_of?(FireWatir::Firefox)
38
- @page.pets.kind_of?(FireWatir::CheckboxGroup).should == true
39
-
40
- elsif @page.b.kind_of?(Watir::IE)
41
- @page.pets.kind_of?(Watir::CheckboxGroup).should == true
42
- end
43
- end
44
-
45
- it 'size retuns checkboxes as items count in a group' do
46
- @page.pets.size.should == 5
47
- end
48
-
49
- it 'values returns array of value attributes for each checkbox in a group' do
50
- @page.pets.values.should == ["cat", "dog", "zook", "zebra", "wumpa"]
51
- end
52
-
53
- it 'selected_values returns array of value attributes of each selected checkbox' do
54
- @page.pets.selected.should == nil
55
- @page.pets.selected_value.should == nil
56
- @page.pets.selected_values.should == []
57
- end
58
-
59
- it 'set String checks the checkbox in a group where value is String' do
60
- @page.pets.set 'dog'
61
- @page.pets.selected.should == 'dog'
62
- @page.pets.selected_value.should == 'dog'
63
- @page.pets.selected_values.should == ['dog']
64
- end
65
-
66
- it 'set String array checks each checkbox by hidden value String' do
67
- @page.pets.set ['dog', 'zebra', 'cat'] # not in order
68
- @page.pets.selected.should == ['cat', 'dog', 'zebra']
69
- @page.pets.selected_value.should == ['cat', 'dog', 'zebra'] # bypass filter
70
- @page.pets.selected_values.should == ['cat', 'dog', 'zebra']
71
- end
72
-
73
- it 'set Fixnum checks checkbox by position in a group. Position is 1 based' do
74
- @page.pets.set 3
75
- @page.pets.selected_values.should == ['zook']
76
- end
77
-
78
- it 'set array of Fixnums checks each checkbox by position' do
79
- @page.pets.set [4,1,2] # not in order
80
- @page.pets.selected_values.should == ["cat", "dog", "zebra"]
81
- end
82
-
83
- end
@@ -1,50 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- describe 'setting and getting values for individual checkboxes with value attributes in face definitions' do
4
-
5
- before do
6
- @page = Watirloo::Page.new
7
- @page.browser.goto testfile('checkbox_group1.html')
8
-
9
- # instance method page.face adds defintion but only to the current instance of the page
10
- # in watir you have to access each checkbox.
11
- # in Watirloo you can access CheckboxGroup as shortcut using
12
- # :pets => [:checkbox_group, 'pets']
13
- @page.face(
14
- :pets_cat => [:checkbox, :name, 'pets', 'cat'],
15
- :pets_dog => [:checkbox, :name, 'pets', 'dog'],
16
- :pets_zook => [:checkbox, :name, 'pets', 'zook'],
17
- :pets_zebra => [:checkbox, :name, 'pets', 'zebra'],
18
- :pets_wumpa => [:checkbox, :name, 'pets', 'wumpa'])
19
- end
20
-
21
- it 'semantic name accesses individual CheckBox' do
22
- if @page.b.kind_of?(FireWatir::Firefox)
23
- @page.pets_cat.kind_of?(FireWatir::CheckBox).should == true
24
-
25
- elsif @page.b.kind_of?(Watir::IE)
26
- @page.pets_cat.kind_of?(Watir::CheckBox).should == true
27
- end
28
- end
29
-
30
- it 'set individual checkbox does not set other checkboxes sharing the same name' do
31
- @page.pets_dog.checked?.should == false
32
- @page.pets_dog.set
33
- @page.pets_dog.checked?.should == true
34
- @page.pets_cat.checked?.should == false
35
- end
36
-
37
- it 'by default all are false. set each unchecked checkbox should have checked? true' do
38
- @page.interfaces.keys.each do |key|
39
- @page.get_face(key).checked?.should == false
40
- end
41
-
42
- @page.interfaces.keys.each do |key|
43
- @page.get_face(key).set
44
- end
45
-
46
- @page.interfaces.keys.each do |key|
47
- @page.get_face(key).checked?.should.be true
48
- end
49
- end
50
- end
@@ -1,20 +0,0 @@
1
- <!--
2
- Document : checbox_group
3
- -->
4
- <!DOCtype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5
- <html>
6
- <head>
7
- <title></title>
8
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9
- </head>
10
- <body>
11
- <h3>Pets CheckboxGroup. Each has value. Acts like MultiSelectList. none, one ore more items can be checked.</h3>
12
- <input name="pets" type="checkbox" value="cat">cat<br />
13
- <input name="pets" type="checkbox" value="dog">dog<br />
14
- <input name="pets" type="checkbox" value="zook">zook<br />
15
- <input name="pets" type="checkbox" value="zebra">zebra<br />
16
- <input name="pets" type="checkbox" value="wumpa">wumpa<br />
17
- <h3>Single CheckboxToggle Only. Acts like RadioGroup on/off switch.</h3>
18
- <input name="singleIndicator" type="checkbox">ToggleMe<br />
19
- </body>
20
- </html>
@@ -1,32 +0,0 @@
1
- <!--
2
- Document : labels
3
- http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL
4
- -->
5
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
6
- <html>
7
- <head>
8
- <title></title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10
- </head>
11
- <body>
12
-
13
- <h3>Implicit label wraps text_field without for attribute. Click does not transfer focus to control</h3>
14
- <form id="wrap_without_for"action="" method="get">
15
- <p>
16
- <label>First Name<INPUT type="text" name="fn"></label>
17
- </p>
18
- <p>
19
- <label><INPUT type="text" name="ln">Last Name</label>
20
- </p>
21
- </form>
22
-
23
- <h3>Explicit Label For Item with Id. Click transfers focus to control associated by id</h3>
24
- <form id="label_for_id"action="" method="get">
25
- <p>
26
- <label for="first_nm">FirstName For</label><INPUT type="text" name="firstname" id="first_nm">
27
- <INPUT type="text" name="lastname" id="last_nm"><label for="last_nm">LastName For</label>
28
- </p>
29
- </form>
30
-
31
- </body>
32
- </html>
@@ -1,41 +0,0 @@
1
- <!--
2
- Document : radio_group
3
- -->
4
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5
- <html>
6
- <head>
7
- <title>radio_groups</title>
8
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9
- </head>
10
- <body>
11
- <h3>wanna eat what?</h3>
12
- <TABLE border="0">
13
- <TBODY>
14
- <TR>
15
- <TD>
16
- <INPUT type="radio" name="food" value="hotdog" />
17
- </TD>
18
- <TD>
19
- Hothund
20
- </TD>
21
- </TR>
22
- <TR>
23
- <TD>
24
- <INPUT type="radio" name="food" value="burger" checked />
25
- </TD>
26
- <TD>
27
- Burgier
28
- </TD>
29
- </TR>
30
- <TR>
31
- <TD>
32
- <INPUT type="radio" name="food" value="tofu" />
33
- </TD>
34
- <TD>
35
- Tofoo
36
- </TD>
37
- </TR>
38
- </TBODY>
39
- </TABLE>
40
- </body>
41
- </html>
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
-
4
- describe "SuperPage" do
5
-
6
- class SuperPage < Watirloo::Page
7
- face 'name' => 'vname'
8
- end
9
-
10
- it 'class interface' do
11
- SuperPage.interfaces.keys.should == ['name']
12
- end
13
-
14
- it 'instance initialized from class interface' do
15
- SuperPage.new.interfaces.keys.should == ['name']
16
- end
17
-
18
- it 'adding interface to instance adds interface to initialize' do
19
- page = SuperPage.new
20
- page.face 'sub' => 'sub' # add new face to instance
21
- page.interfaces.keys.sort.should == %w[name sub] # instnace has now two
22
- end
23
-
24
- it 'but not to class' do
25
- page = SuperPage.new
26
- page.face 'sub' => 'sub'
27
- page.interfaces.keys.sort.should == %w[name sub]
28
- SuperPage.interfaces.keys.should == ['name'] # but the class has still only one
29
- end
30
-
31
- it 'class interface can be updated' do
32
- SuperPage.interfaces.update 'update' => 'vupdate'
33
- SuperPage.interfaces.keys.sort.should == %w[name update]
34
- end
35
-
36
- it 'instance gets interfaces from class but does not get them after updating class' do
37
- page = SuperPage.new
38
- page.interfaces.keys.sort.should == %w[name update] #previous example altered it
39
- SuperPage.interfaces.update 'muddy' => 'vmuddy'
40
- page.interfaces.keys.sort.should == %w[name update] #previous example altered it
41
- end
42
- end
43
-
44
- describe "SuperPage and SubPage" do
45
-
46
- class Page0 < Watirloo::Page
47
- face 'higher' => 'vhigher'
48
- end
49
- class Page1 < Page0
50
- face 'lower' => 'vlower'
51
- end
52
- class Page2 < Page1
53
- face 'lowest' => 'vlowest'
54
- end
55
-
56
- it 'Subpage inherits from Super its interfaces' do
57
- p1 = Page1.new
58
- p1.interfaces.keys.sort.should == %w[higher lower]
59
- end
60
-
61
- it "Super retains its interfaces and is not affected by Subpages" do
62
- p0 = Page0.new
63
- p0.face 'supinst' => 'vsupinst'
64
- p0.interfaces.keys.sort.should == %w[higher supinst]
65
- Page0.interfaces.keys.sort.should == ['higher']
66
-
67
- p1 = Page1.new
68
- p1.face 'subinst' => 'vsubinst'
69
- p1.interfaces.keys.sort.should == %w[higher lower subinst]
70
- Page1.interfaces.keys.sort.should == %w[higher lower]
71
-
72
- # extra checks
73
- p0.interfaces.keys.sort.should == %w[higher supinst] #super not affected by Sub
74
- Page0.interfaces.keys.sort.should == ['higher'] #not affected by P1.instance face
75
- Page2.interfaces.keys.sort.should == %w[higher lower lowest]
76
- end
77
-
78
-
79
- end