druid-ts 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +6 -7
  3. data/Gemfile +0 -5
  4. data/druid.gemspec +2 -1
  5. data/features/area.feature +0 -1
  6. data/features/audio.feature +0 -2
  7. data/features/bold.feature +0 -1
  8. data/features/canvas.feature +0 -2
  9. data/features/div.feature +0 -2
  10. data/features/heading.feature +0 -10
  11. data/features/italic.feature +0 -1
  12. data/features/label.feature +0 -2
  13. data/features/link.feature +0 -2
  14. data/features/list_item.feature +0 -2
  15. data/features/ordered_list.feature +0 -2
  16. data/features/paragraph.feature +0 -2
  17. data/features/span.feature +0 -2
  18. data/features/step_definations/element_steps.rb +2 -2
  19. data/features/step_definations/section_steps.rb +1 -1
  20. data/features/table.feature +0 -2
  21. data/features/table_cell.feature +0 -2
  22. data/features/unordered_list.feature +0 -3
  23. data/features/video.feature +0 -11
  24. data/lib/druid.rb +1 -5
  25. data/lib/druid/accessors.rb +2 -296
  26. data/lib/druid/assist.rb +1 -9
  27. data/lib/druid/elements/button.rb +0 -4
  28. data/lib/druid/elements/check_box.rb +0 -4
  29. data/lib/druid/elements/div.rb +0 -3
  30. data/lib/druid/elements/element.rb +3 -266
  31. data/lib/druid/elements/file_field.rb +0 -3
  32. data/lib/druid/elements/form.rb +0 -9
  33. data/lib/druid/elements/hidden_field.rb +0 -4
  34. data/lib/druid/elements/image.rb +0 -4
  35. data/lib/druid/elements/label.rb +0 -3
  36. data/lib/druid/elements/link.rb +0 -16
  37. data/lib/druid/elements/list_item.rb +0 -4
  38. data/lib/druid/elements/option.rb +0 -6
  39. data/lib/druid/elements/ordered_list.rb +0 -4
  40. data/lib/druid/elements/radio_button.rb +0 -3
  41. data/lib/druid/elements/select_list.rb +0 -26
  42. data/lib/druid/elements/span.rb +0 -4
  43. data/lib/druid/elements/table_cell.rb +0 -3
  44. data/lib/druid/elements/table_row.rb +4 -0
  45. data/lib/druid/elements/text_area.rb +0 -17
  46. data/lib/druid/elements/text_field.rb +0 -7
  47. data/lib/druid/elements/unordered_list.rb +0 -4
  48. data/lib/druid/page_populator.rb +15 -0
  49. data/lib/druid/version.rb +1 -1
  50. data/spec/druid/druid_spec.rb +1 -21
  51. data/spec/druid/elements/area_spec.rb +0 -8
  52. data/spec/druid/elements/bold_spec.rb +0 -9
  53. data/spec/druid/elements/button_spec.rb +0 -8
  54. data/spec/druid/elements/canvas_spec.rb +0 -9
  55. data/spec/druid/elements/check_box_spec.rb +0 -9
  56. data/spec/druid/elements/div_spec.rb +0 -9
  57. data/spec/druid/elements/element_spec.rb +6 -18
  58. data/spec/druid/elements/file_field_spec.rb +0 -9
  59. data/spec/druid/elements/form_spec.rb +0 -9
  60. data/spec/druid/elements/heading_spec.rb +0 -9
  61. data/spec/druid/elements/hidden_field_spec.rb +0 -9
  62. data/spec/druid/elements/image_spec.rb +0 -9
  63. data/spec/druid/elements/itatic_spec.rb +1 -10
  64. data/spec/druid/elements/label_spec.rb +0 -9
  65. data/spec/druid/elements/link_spec.rb +0 -16
  66. data/spec/druid/elements/list_item_spec.rb +0 -9
  67. data/spec/druid/elements/ordered_list_spec.rb +0 -9
  68. data/spec/druid/elements/paragraph_spec.rb +0 -9
  69. data/spec/druid/elements/radio_button_spec.rb +0 -9
  70. data/spec/druid/elements/select_list_spec.rb +0 -9
  71. data/spec/druid/elements/span_spec.rb +0 -9
  72. data/spec/druid/elements/table_cell_spec.rb +0 -9
  73. data/spec/druid/elements/table_row_spec.rb +0 -8
  74. data/spec/druid/elements/table_spec.rb +0 -9
  75. data/spec/druid/elements/text_area_spec.rb +0 -9
  76. data/spec/druid/elements/text_field_spec.rb +0 -9
  77. data/spec/druid/elements/unordered_list_spec.rb +0 -9
  78. data/spec/druid/page_populator_spec.rb +5 -3
  79. metadata +15 -15
@@ -2,22 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class Link < Element
4
4
 
5
- #
6
- # return the href fot the link
7
- #
8
- def href
9
- element.href
10
- end
11
-
12
- protected
13
-
14
- def self.finders
15
- super + [:href, :text, :css, :title]
16
- end
17
-
18
- def self.mapping
19
- super.merge({:link => :text, :link_text => :text})
20
- end
21
5
  end
22
6
 
23
7
  Druid::Elements.tag_to_class[:a] = Druid::Elements::Link
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class ListItem < Element
4
4
 
5
- def self.finders
6
- super + [:text]
7
- end
8
-
9
5
  end
10
6
 
11
7
  Druid::Elements.tag_to_class[:li] = Druid::Elements::ListItem
@@ -2,12 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class Option < Element
4
4
 
5
- #
6
- # returns true if the option is selected
7
- #
8
- def selected?
9
- element.selected?
10
- end
11
5
  end
12
6
 
13
7
  Druid::Elements.tag_to_class[:option] = Druid::Elements::Option
@@ -3,10 +3,6 @@ module Druid
3
3
  class OrderedList < Element
4
4
  attr_accessor :li_element
5
5
 
6
- def self.finders
7
- [:class, :id, :index, :xpath]
8
- end
9
-
10
6
  def [](idx)
11
7
  Druid::Elements::ListItem.new(children[idx])
12
8
  end
@@ -2,9 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class RadioButton < Element
4
4
 
5
- def self.finders
6
- super + [:value, :label]
7
- end
8
5
  #
9
6
  # Select the RadioButton
10
7
  #
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class SelectList < Element
4
4
 
5
- def self.finders
6
- super + [:value, :text, :label]
7
- end
8
-
9
5
  def [](idx)
10
6
  options[idx]
11
7
  end
@@ -14,21 +10,6 @@ module Druid
14
10
  element.options.map { |e| Druid::Elements::Option.new(e)}
15
11
  end
16
12
 
17
- #
18
- # Select a value from the list
19
- #
20
- def select(value)
21
- element.select(value)
22
- end
23
-
24
- #
25
- # Select the options whose value attribute matches the Given
26
- # string
27
- #
28
- def select_value(value)
29
- element.select_value(value)
30
- end
31
-
32
13
  #
33
14
  # @return [Array<String>] An array of strings representing the text of the currently selected options.
34
15
  #
@@ -51,13 +32,6 @@ module Druid
51
32
  element.include? value
52
33
  end
53
34
 
54
- #
55
- # Returns true if any of the selected options' text or label match the given value.
56
- # @param [String, Regexp] value A value
57
- # @return [Boolean]
58
- def selected? value
59
- element.selected? value
60
- end
61
35
  end
62
36
 
63
37
  Druid::Elements.tag_to_class[:select] = Druid::Elements::SelectList
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class Span < Element
4
4
 
5
- def self.finders
6
- [:class, :id, :index, :xpath, :text, :title]
7
- end
8
-
9
5
  end
10
6
 
11
7
  Druid::Elements.tag_to_class[:span] = Druid::Elements::Span
@@ -2,9 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class TableCell < Element
4
4
 
5
- def self.finders
6
- super + [:text]
7
- end
8
5
  end
9
6
 
10
7
  Druid::Elements.tag_to_class[:td] = Druid::Elements::TableCell
@@ -1,3 +1,4 @@
1
+ require 'watir/elements/html_elements'
1
2
  module Druid
2
3
  module Elements
3
4
  class TableRow < Element
@@ -30,6 +31,9 @@ module Druid
30
31
  def find_index_by_title(title)
31
32
  table = element.parent
32
33
  table = table.parent if table.tag_name == 'tbody'
34
+ if table.instance_of? Watir::HTMLElement
35
+ table = table.to_subtype
36
+ end
33
37
  first_row = table[0]
34
38
  first_row.cells.find_index { |column| column.text.include? title}
35
39
  end
@@ -2,9 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class TextArea < Element
4
4
 
5
- def self.finders
6
- super + [:label]
7
- end
8
5
  #
9
6
  # Set the value of the TextArea
10
7
  #
@@ -12,20 +9,6 @@ module Druid
12
9
  element.set(new_value)
13
10
  end
14
11
 
15
- #
16
- # Clear the TextArea
17
- #
18
- def clear
19
- element.clear
20
- end
21
-
22
- #
23
- # append the text to the end of the text in the text area
24
- #
25
- def append(text)
26
- element.append(text)
27
- end
28
-
29
12
  end
30
13
 
31
14
  Druid::Elements.tag_to_class[:textarea] = Druid::Elements::TextArea
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class TextField < Element
4
4
 
5
- def self.finders
6
- super + [:text, :title, :label]
7
- end
8
-
9
5
  #
10
6
  # Set the value of the TextField
11
7
  #
@@ -13,9 +9,6 @@ module Druid
13
9
  element.set(new_value)
14
10
  end
15
11
 
16
- def append text
17
- element.append text
18
- end
19
12
  end
20
13
 
21
14
  Druid::Elements.type_to_class[:text] = Druid::Elements::TextField
@@ -2,10 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class UnOrderedList < Element
4
4
 
5
- def self.finders
6
- [:class, :id, :index, :xpath]
7
- end
8
-
9
5
  def [](idx)
10
6
  Druid::Elements::ListItem.new(children[idx])
11
7
  end
@@ -33,6 +33,7 @@ module Druid
33
33
  populate_checkbox(key, value) if is_checkbox?(key) and is_enabled?(key)
34
34
  populate_radiobuttongroup(key, value) if is_radiobuttongroup?(key)
35
35
  populate_radiobutton(key, value) if is_radiobutton?(key) and is_enabled?(key)
36
+ populate_select_list(key, value) if is_select_list?(key)
36
37
  populate_text(key, value) if is_text?(key) and is_enabled?(key)
37
38
  end
38
39
  end
@@ -56,7 +57,17 @@ module Druid
56
57
  return self.send "select_#{key}", value
57
58
  end
58
59
 
60
+ def populate_select_list(key, value)
61
+ select_element = self.send("#{key}_element")
62
+ if select_element.options.include?(value)
63
+ select_element.select(value)
64
+ else
65
+ select_element.select_value(value)
66
+ end
67
+ end
68
+
59
69
  def is_text?(key)
70
+ return false if is_select_list?(key)
60
71
  respond_to?("#{key}=".to_sym)
61
72
  end
62
73
 
@@ -72,6 +83,10 @@ module Druid
72
83
  respond_to?("select_#{key}".to_sym) and respond_to?("#{key}_values")
73
84
  end
74
85
 
86
+ def is_select_list?(key)
87
+ respond_to?("#{key}_options".to_sym)
88
+ end
89
+
75
90
  def is_enabled?(key)
76
91
  return false if is_radiobuttongroup?(key)
77
92
  return true if (self.send "#{key}_element").tag_name == "textarea"
@@ -1,3 +1,3 @@
1
1
  module Druid
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -85,35 +85,15 @@ describe Druid do
85
85
  end
86
86
 
87
87
  context "when sent a missing method" do
88
- it "should not respond to it if the @root_element doesn't exist" do
89
- expect(nil).to respond_to :to_i
90
- expect(druid.instance_variable_get(:@root_element)).to be nil
91
- expect(druid).not_to respond_to :to_i
92
- expect { druid.to_i }.to raise_error NoMethodError
93
- end
94
88
 
95
89
  it "should respond to it if the @root_element exists and responds" do
96
- expect(druid.instance_variable_get(:@root_element)).to be nil
97
90
  expect(druid).not_to respond_to :bar
98
91
  expect(druid).not_to respond_to :baz
99
- class Foo
100
- def bar
101
- :bar_called
102
- end
103
-
104
- private
105
-
106
- def baz
107
- end
108
- end
92
+ class Foo; def bar; :bar_called; end; private; def baz; end; end
109
93
  druid.instance_variable_set(:@root_element, Foo.new)
110
-
111
94
  expect(druid).to respond_to :bar
112
95
  expect(druid).not_to respond_to :baz
113
96
  expect(druid.bar).to eq :bar_called
114
- expect { druid.baz }.to raise_error NoMethodError
115
- expect(druid.respond_to?(:baz, true)).to be false
116
- expect { druid.send(:baz) }.to raise_error NoMethodError
117
97
  end
118
98
  end
119
99
 
@@ -2,14 +2,6 @@ require 'spec_helper'
2
2
  require 'druid/elements'
3
3
 
4
4
  describe Druid::Elements::Area do
5
- context "when mapping how to find an element" do
6
- it "should map watir types to same" do
7
- [:class, :id, :index, :name, :xpath].each do |t|
8
- identifier = Druid::Elements::Area.identifier_for t => 'value'
9
- expect(identifier.keys.first).to eql t
10
- end
11
- end
12
- end
13
5
 
14
6
  context "implementation" do
15
7
  let(:element) { double('element') }
@@ -4,15 +4,6 @@ require 'druid/elements'
4
4
  describe Druid::Elements::Bold do
5
5
  let(:bold) { Druid::Elements::Bold}
6
6
 
7
- describe "when mapping how to find an element" do
8
- it "should map watir types to same" do
9
- [:class, :id, :idenx, :name, :xpath, :css].each do |t|
10
- identifier = bold.identifier_for t => 'value'
11
- expect(identifier.keys.first).to eql t
12
- end
13
- end
14
- end
15
-
16
7
  describe "interface" do
17
8
  it "should register with tag :b" do
18
9
  expect(Druid::Elements.element_class_for(:b)).to eql Druid::Elements::Bold
@@ -2,14 +2,6 @@ require 'spec_helper'
2
2
  require 'druid/elements'
3
3
 
4
4
  describe Druid::Elements::Button do
5
- describe "when mapping how to find an element" do
6
- it "should map watir types to same" do
7
- [:class, :id, :index, :name, :value, :xpath, :src, :alt, :css].each do |t|
8
- identifier = Druid::Elements::Button.identifier_for t => 'value'
9
- expect(identifier.keys.first).to eql t
10
- end
11
- end
12
- end
13
5
 
14
6
  describe "interface" do
15
7
  it "should register with type :submit" do
@@ -2,15 +2,6 @@ require 'spec_helper'
2
2
  require 'druid/elements'
3
3
 
4
4
  describe Druid::Elements::Canvas do
5
- context "when mapping how to find an element" do
6
- it "should map watir types to same" do
7
- [:class, :id, :index, :name, :xpath].each do |t|
8
- identifier = Druid::Elements::Canvas.identifier_for t => 'value'
9
- expect(identifier.keys.first).to eql t
10
- end
11
- end
12
- end
13
-
14
5
  context "implementation" do
15
6
  let(:element) { double('canvas_element') }
16
7
  let(:canvas) { Druid::Elements::Canvas.new(element) }
@@ -2,15 +2,6 @@ require 'spec_helper'
2
2
  require 'druid/elements'
3
3
 
4
4
  describe Druid::Elements::CheckBox do
5
- describe "when mapping how to find an element" do
6
- it "should map watir types to same" do
7
- [:class, :id, :index, :name, :xpath, :value].each do |t|
8
- identifier = Druid::Elements::CheckBox.identifier_for t => 'value'
9
- expect(identifier.keys.first).to eql t
10
- end
11
- end
12
- end
13
-
14
5
  describe "interface" do
15
6
  let(:element) { double 'element' }
16
7
  let(:checkbox) { Druid::Elements::CheckBox.new(element) }
@@ -2,15 +2,6 @@ require 'spec_helper'
2
2
  require 'druid/elements'
3
3
 
4
4
  describe Druid::Elements::Div do
5
- describe "when mapping how to find an element" do
6
- it "should map watir types to same" do
7
- [:class, :id, :text, :index, :xpath, :title].each do |t|
8
- identifier = Druid::Elements::Div.identifier_for t => 'value'
9
- expect(identifier.keys.first).to eql t
10
- end
11
- end
12
- end
13
-
14
5
  describe "interface" do
15
6
  it "should register with tag :div" do
16
7
  expect(Druid::Elements.element_class_for(:div)).to be Druid::Elements::Div
@@ -11,16 +11,6 @@ describe Druid::Elements::Element do
11
11
  end
12
12
  end
13
13
 
14
- context "when building the identifiers" do
15
- it "should build xpath when finding elements by name were not supported" do
16
- ['table', 'span', 'div', 'td', 'li', 'ol', 'ul'].each do |tag|
17
- how = {:tag_name => tag, :name => 'blah'}
18
- result = Druid::Elements::Element.identifier_for how
19
- expect(result[:xpath]).to eql ".//#{tag}[@name='blah']"
20
- end
21
- end
22
- end
23
-
24
14
  context "on a druid" do
25
15
  it "should know when it is visible" do
26
16
  expect(we).to receive(:visible?).and_return(true)
@@ -93,22 +83,25 @@ describe Druid::Elements::Element do
93
83
  end
94
84
 
95
85
  it "should be able to block until it is visible" do
86
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
96
87
  expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not visible in 10 seconds")
97
88
  element.when_visible(10)
98
89
  end
99
90
 
100
91
  it "should return the element when it is visible" do
92
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
101
93
  expect(we).to receive(:wait_until).with(timeout: 10, message: "Element not visible in 10 seconds")
102
94
  expect(element.when_visible(10)).to eq element
103
95
  end
104
96
 
105
97
  it "should be able to block until it is not visible" do
98
+ allow(we).to receive(:wait_until).with(timeout: 10, message: "Element not present in 10 seconds")
106
99
  expect(we).to receive(:wait_while).with(timeout: 10, message: "Element still visible after 10 seconds")
107
100
  element.when_not_visible(10)
108
101
  end
109
102
 
110
103
  it "should be able to block until a user define event fires true" do
111
- expect(Watir::Wait).to receive(:until).with(timeout: 10, message: "Element blah")
104
+ expect(we).to receive(:wait_until).with(timeout: 10, message: "Element blah")
112
105
  element.wait_until(10, "Element blah") {true}
113
106
  end
114
107
 
@@ -137,19 +130,14 @@ describe Druid::Elements::Element do
137
130
  expect(element.style('class')).to eql "tim"
138
131
  end
139
132
 
140
- it "should inspect element" do
141
- expect(we).to receive(:inspect)
142
- element.inspect
143
- end
144
-
145
133
  it "should know if an element is focused" do
146
134
  expect(we).to receive(:focused?).and_return(true)
147
- expect(element).to be_focused
135
+ expect(element.focused?).to be true
148
136
  end
149
137
 
150
138
  it "should know if an element is not focuesd" do
151
139
  expect(we).to receive(:focused?).and_return(false)
152
- expect(element).to_not be_focused
140
+ expect(element.focused?).to_not be true
153
141
  end
154
142
 
155
143
  it "should be able to fire event" do