Module: Insite::CommonMethods
- Included in:
- Component, ComponentCollection, DefinedPage, Element, UndefinedPage
- Defined in:
- lib/insite/methods/common_methods.rb
Instance Method Summary collapse
-
#document(xpath = nil) ⇒ Object
(also: #nokogiri)
Returns a Nokogiri document for the object ONLY.
-
#inspect ⇒ Object
Returns a string representation of the page.
- #update_object(hash_args = {}) ⇒ Object
Instance Method Details
#document(xpath = nil) ⇒ Object Also known as: nokogiri
Returns a Nokogiri document for the object ONLY. So no need to specify a relative path.
6 7 8 9 10 11 12 |
# File 'lib/insite/methods/common_methods.rb', line 6 def document(xpath = nil) if xpath Nokogiri::HTML(html).xpath(xpath) else Nokogiri::HTML(html) end end |
#inspect ⇒ Object
Returns a string representation of the page.
16 17 18 |
# File 'lib/insite/methods/common_methods.rb', line 16 def inspect "#<#{self.class.name}:#{object_id} @url=#{@browser.url}>" end |
#update_object(hash_args = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/insite/methods/common_methods.rb', line 61 def update_object(hash_args = {}) rescues = [ Watir::Exception::ObjectDisabledException, Watir::Exception::UnknownObjectException, Selenium::WebDriver::Error::ElementNotVisibleError, Selenium::WebDriver::Error::UnknownError ] failed = [] hash_args.each do |k, v| begin k = k.to_sym if @page_elements.include?(k) elem = public_send(k) if [Insite::Alert, Insite::FileField, Insite::TextField, Insite::TextArea].include? elem.class elem.set v elsif [Insite::Select].include? elem.class elem.select v elsif [Insite::Anchor, Insite::Button].include? elem.class case v when Symbol elem.public_send v when TrueClass elem.click when FalseClass # Do nothing here. else raise ArgumentError, "Unsupported argument for #{elem.class}: '#{v}'" end elsif elem.is_a?(Insite::Radio) case v when Symbol elem.public_send v when TrueClass 3.times do elem.set break if elem.set? sleep 0.5 end when FalseClass raise ArgumentError, "Unsupported argument for #{elem.class}: '#{v}' \ (You can only set a radio button, so false is not a valid argument.)" else raise ArgumentError, "Unsupported argument for #{elem.class}: '#{v}'" end elsif elem.is_a?(Insite::CheckBox) case v when Symbol elem.public_send v when TrueClass 3.times do elem.set break if elem.set? sleep 0.5 end when FalseClass 3.times do elem.clear break if !elem.set? sleep 0.5 end elem.clear else raise ArgumentError, "Unsupported argument for #{elem.class}: '#{v}'" end else case v when Symbol elem.public_send v when TrueClass elem.set when FalseClass elem.clear else raise ArgumentError, "Unsupported argument for #{elem.class}: '#{v}'" end end elsif @component_elements.include?(k) w = public_send(k) begin w.update(v) rescue => e begin if v.is_a?(Array) public_send(k).update(v) else public_send(k).update(*v) end rescue => e2 raise ArgumentError, "Dynamic method call failed for #{k}.", e2.backtrace.join("\n") end end else begin if v.is_a?(Array) public_send(k, *v) else public_send(k, v) end rescue => e begin if v.is_a?(Array) public_send(k).update(v) else public_send(k).update(*v) end rescue => e2 raise ArgumentError, "Dynamic method call failed for #{k}.", e2.backtrace end end end rescue => e if rescues.any? { |err| e.is_a?(err) } unless failed.include?(k) puts "Rescued #{e.class} when trying to update #{k}. Sleeping 5 seconds and then trying again." failed << k sleep 5 redo end else raise e, "Failure trying to update #{k} with #{v.class}: #{v}:\n" + e.backtrace.join("\n") end end sleep 0.2 end sleep 1 hash_args end |