druid-ts 1.2.4 → 1.2.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +21 -2
  3. data/Gemfile +1 -1
  4. data/druid.gemspec +3 -3
  5. data/features/element.feature +0 -5
  6. data/features/frames.feature +4 -0
  7. data/features/html/static_elements.html +11 -0
  8. data/features/populate_page_with.feature +25 -0
  9. data/features/select_list.feature +1 -0
  10. data/features/step_definations/audio_steps.rb +1 -1
  11. data/features/step_definations/element_steps.rb +0 -4
  12. data/features/step_definations/frame_steps.rb +35 -0
  13. data/features/step_definations/populate_page_with_steps.rb +3 -0
  14. data/features/step_definations/select_list_steps.rb +4 -0
  15. data/features/step_definations/table_steps.rb +19 -0
  16. data/features/support/page.rb +2 -0
  17. data/features/table.feature +21 -0
  18. data/lib/druid.rb +0 -1
  19. data/lib/druid/assist.rb +8 -5
  20. data/lib/druid/elements/area.rb +0 -20
  21. data/lib/druid/elements/check_box.rb +0 -20
  22. data/lib/druid/elements/element.rb +73 -64
  23. data/lib/druid/elements/file_field.rb +0 -6
  24. data/lib/druid/elements/hidden_field.rb +0 -4
  25. data/lib/druid/elements/image.rb +0 -7
  26. data/lib/druid/elements/media.rb +0 -34
  27. data/lib/druid/elements/ordered_list.rb +8 -21
  28. data/lib/druid/elements/radio_button.rb +0 -13
  29. data/lib/druid/elements/select_list.rb +2 -11
  30. data/lib/druid/elements/table.rb +41 -16
  31. data/lib/druid/elements/table_row.rb +21 -17
  32. data/lib/druid/elements/text_area.rb +0 -7
  33. data/lib/druid/elements/text_field.rb +0 -7
  34. data/lib/druid/elements/unordered_list.rb +9 -22
  35. data/lib/druid/javascript_framework_facade.rb +1 -1
  36. data/lib/druid/locator_generator.rb +153 -147
  37. data/lib/druid/page_populator.rb +44 -37
  38. data/lib/druid/version.rb +1 -1
  39. data/spec/druid/accessors_spec.rb +3 -3
  40. data/spec/druid/elements/check_box_spec.rb +0 -15
  41. data/spec/druid/elements/element_spec.rb +77 -78
  42. data/spec/druid/elements/file_field_spec.rb +0 -5
  43. data/spec/druid/elements/media_spec.rb +0 -49
  44. data/spec/druid/elements/ordered_list_spec.rb +24 -20
  45. data/spec/druid/elements/radio_button_spec.rb +0 -10
  46. data/spec/druid/elements/table_row_spec.rb +12 -12
  47. data/spec/druid/elements/table_spec.rb +29 -25
  48. data/spec/druid/elements/text_area_spec.rb +0 -4
  49. data/spec/druid/elements/text_field_spec.rb +0 -5
  50. data/spec/druid/elements/unordered_list_spec.rb +25 -20
  51. data/spec/druid/javascript_framework_facade_spec.rb +1 -1
  52. data/spec/druid/page_populator_spec.rb +34 -4
  53. metadata +15 -18
  54. data/lib/druid/core_ext/string.rb +0 -5
  55. data/spec/druid/elements/area_spec.rb +0 -25
  56. data/spec/druid/elements/canvas_spec.rb +0 -19
  57. data/spec/druid/elements/video_spec.rb +0 -25
@@ -2,12 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class FileField < Element
4
4
 
5
- #
6
- # Set the value of the FileField
7
- #
8
- def value=(new_value)
9
- element.set(new_value)
10
- end
11
5
  end
12
6
 
13
7
  Druid::Elements.type_to_class[:file] = Druid::Elements::FileField
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class HiddenField < Element
4
4
 
5
- def click
6
- raise "click is not available on hidden field element with watir"
7
- end
8
-
9
5
  end
10
6
 
11
7
  Druid::Elements.type_to_class[:hidden] = Druid::Elements::HiddenField
@@ -2,13 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class Image < Element
4
4
 
5
- def width
6
- element.width
7
- end
8
-
9
- def height
10
- element.height
11
- end
12
5
  end
13
6
 
14
7
  Druid::Elements.tag_to_class[:img] = Druid::Elements::Image
@@ -2,44 +2,10 @@ module Druid
2
2
  module Elements
3
3
  class Media < Element
4
4
 
5
- def autoplay?
6
- attribute(:autoplay)
7
- end
8
-
9
5
  def has_controls?
10
6
  attribute(:controls)
11
7
  end
12
8
 
13
- def paused?
14
- attribute(:paused)
15
- end
16
-
17
- def duration
18
- duration = attribute(:duration)
19
- return duration.to_f if duration
20
- end
21
-
22
- def volume
23
- volume = attribute(:volume)
24
- return volume.to_i if volume
25
- end
26
-
27
- def ended?
28
- attribute(:ended)
29
- end
30
-
31
- def seeking?
32
- attribute(:seeking)
33
- end
34
-
35
- def loop?
36
- attribute(:loop)
37
- end
38
-
39
- def muted?
40
- attribute(:muted)
41
- end
42
-
43
9
  end
44
10
  end
45
11
  end
@@ -4,35 +4,22 @@ module Druid
4
4
  attr_accessor :li_element
5
5
 
6
6
  def [](idx)
7
- Druid::Elements::ListItem.new(children[idx])
7
+ list_items[idx]
8
8
  end
9
9
 
10
10
  def items
11
- children.size
11
+ list_items.size
12
12
  end
13
13
 
14
- def each
15
- for index in 1..self.items do
16
- yield self[index-1]
17
- end
14
+ def each(&block)
15
+ list_items.each(&block)
18
16
  end
19
17
 
18
+ #
19
+ # Return Array of ListItem objects that are children of the OrderedList
20
+ #
20
21
  def list_items
21
- children.collect do |obj|
22
- Druid::Elements::ListItem.new(obj)
23
- end
24
- end
25
-
26
- protected
27
-
28
- def child_xpath
29
- "./child::li"
30
- end
31
-
32
- private
33
-
34
- def children
35
- element.ols(:xpath => child_xpath)
22
+ @list_items ||= children(tag_name: 'li')
36
23
  end
37
24
 
38
25
  end
@@ -2,19 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class RadioButton < Element
4
4
 
5
- #
6
- # Select the RadioButton
7
- #
8
- def select
9
- element.set
10
- end
11
-
12
- #
13
- # Return if it is selected
14
- #
15
- def selected?
16
- element.set?
17
- end
18
5
  end
19
6
 
20
7
  Druid::Elements.type_to_class[:radio] = Druid::Elements::RadioButton
@@ -14,22 +14,13 @@ module Druid
14
14
  # @return [Array<String>] An array of strings representing the text of the currently selected options.
15
15
  #
16
16
  def selected_options
17
- element.selected_options.map { |e| e.text }.compact
17
+ element.selected_options.map(&:text).compact
18
18
  end
19
19
 
20
20
  #
21
21
  # @return [Array<String>] An array of strings representing the value of the currently selected options.
22
22
  def selected_values
23
- element.selected_options.map { |e| e.value }.compact
24
- end
25
-
26
- #
27
- # Returns true if the select list has one or more options where text or label matches the given value.
28
- #
29
- # @param [String, Regexp] value A value
30
- # @return [Boolean]
31
- def include? value
32
- element.include? value
23
+ element.selected_options.map(&:value).compact
33
24
  end
34
25
 
35
26
  end
@@ -7,24 +7,27 @@ module Druid
7
7
  # will be matched with the text from any column. The text can be
8
8
  # a substring of the full column text.
9
9
  #
10
- # @return [Druid::Elements::Table]
10
+ # @return [Druid::Elements::TableRow]
11
11
  #
12
- def [](idx)
13
- idx = find_index_by_title(idx) if idx.kind_of?(String)
14
- return nil unless idx
15
- Druid::Elements::TableRow.new(element[idx])
12
+ def [](what)
13
+ idx = find_index(what)
14
+ idx && row_items[idx]
16
15
  end
16
+
17
17
  #
18
18
  # Returns the number of rows in the table.
19
19
  #
20
20
  def rows
21
- element.rows.size
21
+ row_items.size
22
22
  end
23
23
 
24
- def each
25
- for index in 1..self.rows do
26
- yield self[index-1]
27
- end
24
+ #
25
+ # iterator that yields with a Druid::Elements::TableRow
26
+ #
27
+ # @return [Druid::Elements::TableRow]
28
+ #
29
+ def each(&block)
30
+ row_items.each(&block)
28
31
  end
29
32
 
30
33
  #
@@ -46,17 +49,39 @@ module Druid
46
49
  end
47
50
 
48
51
  #
49
- # return the table as hashes
52
+ # Returns the Array of values(String) in a column for the index provided. Index
53
+ # is zero based. If the index provided is a String then it
54
+ # will be matched with the text from the header. The text can be a substring of the full header text
50
55
  #
51
- def hashes
52
- element.hashes
56
+ def column_values(what)
57
+ idx = find_index_of_header(what)
58
+ idx && row_items.drop(1).collect{ |row| row.cell(index: idx).text }
53
59
  end
54
60
 
55
61
  private
56
62
 
57
- def find_index_by_title(row_title)
58
- element.rows.find_index do |row|
59
- row.cells.any? { |col| col.text.include? row_title}
63
+ def row_items
64
+ meth = stragegy == :descendants ? :trs : :rows
65
+ @row_items ||= element.send(meth).map do |obj|
66
+ Druid::Elements::TableRow.new(obj)
67
+ end
68
+ end
69
+
70
+ def stragegy
71
+ :children
72
+ end
73
+
74
+ def find_index_of_header(what)
75
+ return what if what.is_a? Integer
76
+ row_items[0].cells.find_index do |cell|
77
+ cell.text.include? Regexp.escape(what)
78
+ end
79
+ end
80
+
81
+ def find_index(what)
82
+ return what if what.is_a? Integer
83
+ row_items.find_index do |row|
84
+ row.cell(text: /#{Regexp.escape(what)}/).exist?
60
85
  end
61
86
  end
62
87
 
@@ -8,34 +8,38 @@ module Druid
8
8
  # is zero based. If the index provided is a String then it
9
9
  # will be matched with the text from the columns in the first row.
10
10
  #
11
- def [](idx)
12
- idx = find_index_by_title(idx) if idx.kind_of?(String)
13
- return nil unless idx && columns >= idx + 1
14
- Druid::Elements::TableCell.new(element[idx])
11
+ def [](what)
12
+ idx = find_index(what)
13
+ idx && cell_items[idx]
15
14
  end
15
+
16
16
  #
17
- # Returns the number of rows in the table.
17
+ # Returns the number of colums in the table
18
18
  #
19
19
  def columns
20
- element.cells.size
20
+ cell_items.size
21
21
  end
22
22
 
23
- def each
24
- for index in 1..self.columns do
25
- yield self[index-1]
26
- end
23
+ #
24
+ # iterator that yields with a Druid::Elements::TableCell
25
+ #
26
+ def each(&block)
27
+ cell_items.each(&block)
27
28
  end
28
29
 
29
30
  private
30
31
 
31
- def find_index_by_title(title)
32
- table = element.parent
33
- table = table.parent if table.tag_name == 'tbody'
34
- if table.instance_of? Watir::HTMLElement
35
- table = table.to_subtype
32
+ def cell_items
33
+ @cell_items ||= element.cells.map do |obj|
34
+ Druid::Elements::TableCell.new(obj)
35
+ end
36
+ end
37
+
38
+ def find_index(what)
39
+ return what if what.is_a? Integer
40
+ parent(tag_name: 'table').headers.find_index do |header|
41
+ header.text.include? what
36
42
  end
37
- first_row = table[0]
38
- first_row.cells.find_index { |column| column.text.include? title}
39
43
  end
40
44
 
41
45
  end
@@ -2,13 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class TextArea < Element
4
4
 
5
- #
6
- # Set the value of the TextArea
7
- #
8
- def value=(new_value)
9
- element.set(new_value)
10
- end
11
-
12
5
  end
13
6
 
14
7
  Druid::Elements.tag_to_class[:textarea] = Druid::Elements::TextArea
@@ -2,13 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class TextField < Element
4
4
 
5
- #
6
- # Set the value of the TextField
7
- #
8
- def value=(new_value)
9
- element.set(new_value)
10
- end
11
-
12
5
  end
13
6
 
14
7
  Druid::Elements.type_to_class[:text] = Druid::Elements::TextField
@@ -2,41 +2,28 @@ module Druid
2
2
  module Elements
3
3
  class UnOrderedList < Element
4
4
 
5
+ #
6
+ # @return [Druid::Elements::ListItem]
7
+ #
5
8
  def [](idx)
6
- Druid::Elements::ListItem.new(children[idx])
9
+ list_items[idx]
7
10
  end
8
11
 
9
12
  def items
10
- children.size
13
+ list_items.size
11
14
  end
12
15
 
13
- def each
14
- for index in 1..self.items do
15
- yield self[index-1]
16
- end
16
+ def each(&block)
17
+ list_items.each(&block)
17
18
  end
18
19
 
19
20
  #
20
- # return the ListItem objects that are children of the
21
- # UnOrderedList
21
+ # Return Array of ListItem objects that are children of the UnorderedList
22
22
  #
23
23
  def list_items
24
- children.collect do |obj|
25
- Druid::Elements::ListItem.new(obj)
26
- end
24
+ @list_items ||= children(tag_name: 'li')
27
25
  end
28
26
 
29
- protected
30
-
31
- def child_xpath
32
- "./child::li"
33
- end
34
-
35
- private
36
-
37
- def children
38
- element.uls(:xpath => child_xpath)
39
- end
40
27
  end
41
28
 
42
29
  Druid::Elements.tag_to_class[:ul] = Druid::Elements::UnOrderedList
@@ -65,7 +65,7 @@ module Druid
65
65
  end
66
66
 
67
67
  def unknown_framework(framework)
68
- "You specified the Javascript framework #{framework} and it is unknow to the system"
68
+ "You specified the Javascript framework #{framework} and it is unknown to the system"
69
69
  end
70
70
 
71
71
  def invalid_framework
@@ -1,154 +1,160 @@
1
1
  module Druid
2
2
  module LocatorGenerator
3
3
 
4
- BASIC_ELEMENTS = [:abbr,
5
- :address,
6
- :animate,
7
- :animate_motion,
8
- :animate_transform,
9
- :article,
10
- :as,
11
- :aside,
12
- :base,
13
- :bdi,
14
- :bdo,
15
- :blockquote,
16
- :body,
17
- :br,
18
- :caption,
19
- :circle,
20
- :cite,
21
- :code,
22
- :col,
23
- :colgroup,
24
- :command,
25
- :cursor,
26
- :data,
27
- :datalist,
28
- :dd,
29
- :defs,
30
- :del,
31
- :desc,
32
- :details,
33
- :dfn,
34
- :dialog,
35
- :discard,
36
- :dl,
37
- :dt,
38
- :ellipse,
39
- :em,
40
- :embed,
41
- :fieldset,
42
- :figcaption,
43
- :figure,
44
- :foot,
45
- :footer,
46
- :foreign_object,
47
- :g,
48
- :head,
49
- :header,
50
- :hgroup,
51
- :hr,
52
- :html,
53
- :ins,
54
- :kbd,
55
- :keygen,
56
- :legend,
57
- :line,
58
- :linear_gradient,
59
- :main,
60
- :map,
61
- :mark,
62
- :marker,
63
- :menu,
64
- :menuitem,
65
- :mesh_gradient,
66
- :mesh_patch,
67
- :mesh_row,
68
- :meta,
69
- :metadata,
70
- :meter,
71
- :mpath,
72
- :nav,
73
- :noscript,
74
- :object,
75
- :optgroup,
76
- :output,
77
- :p,
78
- :param,
79
- :path,
80
- :pattern,
81
- :polygon,
82
- :polyline,
83
- :pre,
84
- :progress,
85
- :q,
86
- :radial_gradient,
87
- :rect,
88
- :rp,
89
- :rt,
90
- :ruby,
91
- :s,
92
- :samp,
93
- :script,
94
- :section,
95
- :small,
96
- :source,
97
- :stop,
98
- :strong,
99
- :style,
100
- :sub,
101
- :summary,
102
- :sup,
103
- :switch,
104
- :symbol,
105
- :template,
106
- :text_path,
107
- :thread,
108
- :time,
109
- :title,
110
- :track,
111
- :tspan,
112
- :u,
113
- :use,
114
- :var,
115
- :view,
116
- :wbr]
4
+ BASIC_ELEMENTS = %i(
5
+ abbr
6
+ address
7
+ animate
8
+ animate_motion
9
+ animate_transform
10
+ article
11
+ as
12
+ aside
13
+ base
14
+ bdi
15
+ bdo
16
+ blockquote
17
+ body
18
+ br
19
+ caption
20
+ circle
21
+ cite
22
+ code
23
+ col
24
+ colgroup
25
+ command
26
+ cursor
27
+ data
28
+ datalist
29
+ dd
30
+ defs
31
+ del
32
+ desc
33
+ details
34
+ dfn
35
+ dialog
36
+ discard
37
+ dl
38
+ dt
39
+ ellipse
40
+ em
41
+ embed
42
+ fieldset
43
+ figcaption
44
+ figure
45
+ font
46
+ footer
47
+ foreign_object
48
+ g
49
+ head
50
+ header
51
+ hgroup
52
+ hr
53
+ html
54
+ ins
55
+ kbd
56
+ keygen
57
+ legend
58
+ line
59
+ linear_gradient
60
+ main
61
+ map
62
+ mark
63
+ marker
64
+ menu
65
+ menuitem
66
+ mesh_gradient
67
+ mesh_patch
68
+ mesh_row
69
+ meta
70
+ metadata
71
+ meter
72
+ mpath
73
+ nav
74
+ noscript
75
+ object
76
+ optgroup
77
+ output
78
+ p
79
+ param
80
+ path
81
+ pattern
82
+ polygon
83
+ polyline
84
+ pre
85
+ progress
86
+ q
87
+ radial_gradient
88
+ rect
89
+ rp
90
+ rt
91
+ ruby
92
+ s
93
+ samp
94
+ script
95
+ section
96
+ set
97
+ small
98
+ source
99
+ stop
100
+ strong
101
+ style
102
+ sub
103
+ summary
104
+ sup
105
+ switch
106
+ symbol
107
+ template
108
+ text_path
109
+ thread
110
+ time
111
+ title
112
+ track
113
+ tspan
114
+ u
115
+ use
116
+ var
117
+ view
118
+ wbr
119
+ )
117
120
 
118
- ADVANCED_ELEMENTS = [:text_field,
119
- :hidden_field,
120
- :text_area,
121
- :select_list,
122
- :link,
123
- :checkbox,
124
- :radio_button,
125
- :button,
126
- :div,
127
- :span,
128
- :table,
129
- :cell,
130
- :row,
131
- :image,
132
- :form,
133
- :list_item,
134
- :unordered_list,
135
- :ordered_list,
136
- :h1,
137
- :h2,
138
- :h3,
139
- :h4,
140
- :h5,
141
- :h6,
142
- :paragraph,
143
- :label,
144
- :file_field,
145
- :area,
146
- :canvas,
147
- :audio,
148
- :video,
149
- :b,
150
- :i,
151
- :svg]
121
+
122
+ ADVANCED_ELEMENTS = %i(
123
+ text_field
124
+ hidden_field
125
+ text_area
126
+ select_list
127
+ link
128
+ checkbox
129
+ radio_button
130
+ button
131
+ div
132
+ span
133
+ table
134
+ cell
135
+ row
136
+ image
137
+ form
138
+ list_item
139
+ ordered_list
140
+ unordered_list
141
+ h1
142
+ h2
143
+ h3
144
+ h4
145
+ h5
146
+ h6
147
+ paragraph
148
+ label
149
+ file_field
150
+ area
151
+ canvas
152
+ audio
153
+ video
154
+ b
155
+ i
156
+ svg
157
+ )
152
158
 
153
159
  def self.generate_locators(target)
154
160
  ADVANCED_ELEMENTS.each do |tag|