unobtainium-multifind 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +5 -5
- data/lib/unobtainium-multifind/multifind.rb +33 -22
- data/lib/unobtainium-multifind/version.rb +1 -1
- data/spec/module_spec.rb +53 -0
- data/unobtainium-multifind.gemspec +1 -1
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c8353b1d5e748ec3304a0279b370b43a78914df5
         | 
| 4 | 
            +
              data.tar.gz: a73f7d17ed12dccace0cfb453874373f5bc6acb1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 89196e5772927c51b4e0a07700a2b9dc348380ec2633b6fe779d1aaf2cf9050777b8a4c005e0c9c90a8163bc02e6f17fee39220c5043a6fe06032d3b9341760f
         | 
| 7 | 
            +
              data.tar.gz: b7f000cd8f7159f3ba083a629437953e5a70b7e15e1a2ec8d798a84f843c1047dec7611cb6d2228591ceab8113c3ef8382293ab8c9d0e17cd652deb1a156e1e7
         | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                unobtainium-multifind (0. | 
| 4 | 
            +
                unobtainium-multifind (0.3.0)
         | 
| 5 5 | 
             
                  unobtainium (~> 0.5)
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| @@ -35,8 +35,8 @@ GEM | |
| 35 35 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 36 36 | 
             
                  rspec-support (~> 3.4.0)
         | 
| 37 37 | 
             
                rspec-support (3.4.1)
         | 
| 38 | 
            -
                rubocop (0. | 
| 39 | 
            -
                  parser (>= 2.3.0 | 
| 38 | 
            +
                rubocop (0.40.0)
         | 
| 39 | 
            +
                  parser (>= 2.3.1.0, < 3.0)
         | 
| 40 40 | 
             
                  powerpack (~> 0.1)
         | 
| 41 41 | 
             
                  rainbow (>= 1.99.1, < 3.0)
         | 
| 42 42 | 
             
                  ruby-progressbar (~> 1.7)
         | 
| @@ -68,11 +68,11 @@ DEPENDENCIES | |
| 68 68 | 
             
              phantomjs
         | 
| 69 69 | 
             
              rake (~> 11.1)
         | 
| 70 70 | 
             
              rspec (~> 3.4)
         | 
| 71 | 
            -
              rubocop (~> 0. | 
| 71 | 
            +
              rubocop (~> 0.40)
         | 
| 72 72 | 
             
              selenium-webdriver
         | 
| 73 73 | 
             
              simplecov (~> 0.11)
         | 
| 74 74 | 
             
              unobtainium-multifind!
         | 
| 75 75 | 
             
              yard (~> 0.8)
         | 
| 76 76 |  | 
| 77 77 | 
             
            BUNDLED WITH
         | 
| 78 | 
            -
               1.12. | 
| 78 | 
            +
               1.12.3
         | 
| @@ -36,6 +36,10 @@ module Unobtainium | |
| 36 36 | 
             
                    # that Selenium::WebDriver::Element responds to, or :exists? if you only
         | 
| 37 37 | 
             
                    # care whether the element exists.
         | 
| 38 38 | 
             
                    check_element: :displayed?,
         | 
| 39 | 
            +
                    # The default method to perform the actual find is :find_element, but
         | 
| 40 | 
            +
                    # you can override this here. The most sensible case would be to use
         | 
| 41 | 
            +
                    # :find_elements instead, of course.
         | 
| 42 | 
            +
                    find_method: :find_element,
         | 
| 39 43 | 
             
                  }.freeze
         | 
| 40 44 |  | 
| 41 45 | 
             
                  class << self
         | 
| @@ -54,9 +58,9 @@ module Unobtainium | |
| 54 58 |  | 
| 55 59 | 
             
                  ##
         | 
| 56 60 | 
             
                  # Find multiple elements. Each argument is a Hash of selector options
         | 
| 57 | 
            -
                  # that are passed to  | 
| 58 | 
            -
                  # the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash | 
| 59 | 
            -
                  # the #multifind method.
         | 
| 61 | 
            +
                  # that are passed to options[:find_method]. If one argument contains keys
         | 
| 62 | 
            +
                  # from the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash
         | 
| 63 | 
            +
                  # for the #multifind method.
         | 
| 60 64 | 
             
                  # @return Array of found elements or nil entries if no matching element
         | 
| 61 65 | 
             
                  #   was found.
         | 
| 62 66 | 
             
                  def multifind(*args)
         | 
| @@ -67,7 +71,7 @@ module Unobtainium | |
| 67 71 | 
             
                    results = []
         | 
| 68 72 | 
             
                    selectors.each do |selector|
         | 
| 69 73 | 
             
                      begin
         | 
| 70 | 
            -
                        results <<  | 
| 74 | 
            +
                        results << send(options[:find_method], selector)
         | 
| 71 75 | 
             
                      rescue ::Selenium::WebDriver::Error::NoSuchElementError => err
         | 
| 72 76 | 
             
                        if options[:raise_on_error]
         | 
| 73 77 | 
             
                          raise
         | 
| @@ -153,24 +157,13 @@ module Unobtainium | |
| 153 157 | 
             
                    end
         | 
| 154 158 |  | 
| 155 159 | 
             
                    # Filter all results according to the :check_element option
         | 
| 156 | 
            -
                    filtered =  | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
                         | 
| 161 | 
            -
                      end
         | 
| 162 | 
            -
                      if result.is_a?(::Selenium::WebDriver::Error::NoSuchElementError)
         | 
| 163 | 
            -
                        filtered << result
         | 
| 164 | 
            -
                        next
         | 
| 165 | 
            -
                      end
         | 
| 166 | 
            -
             | 
| 167 | 
            -
                      # Run check_element
         | 
| 168 | 
            -
                      if result.send(options[:check_element])
         | 
| 169 | 
            -
                        filtered << result
         | 
| 170 | 
            -
                        next
         | 
| 160 | 
            +
                    filtered = results.map do |result|
         | 
| 161 | 
            +
                      if result.is_a? Array
         | 
| 162 | 
            +
                        next result.map do |inner|
         | 
| 163 | 
            +
                          next apply_filter(inner, options)
         | 
| 164 | 
            +
                        end
         | 
| 171 165 | 
             
                      end
         | 
| 172 | 
            -
             | 
| 173 | 
            -
                      filtered << nil
         | 
| 166 | 
            +
                      next apply_filter(result, options)
         | 
| 174 167 | 
             
                    end
         | 
| 175 168 |  | 
| 176 169 | 
             
                    return filtered
         | 
| @@ -205,10 +198,28 @@ module Unobtainium | |
| 205 198 | 
             
                    # or :last. An empty result is appropriate.
         | 
| 206 199 | 
             
                    return []
         | 
| 207 200 | 
             
                  end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                  ##
         | 
| 203 | 
            +
                  # Applies the :check_element filter
         | 
| 204 | 
            +
                  def apply_filter(elem, options)
         | 
| 205 | 
            +
                    if elem.nil?
         | 
| 206 | 
            +
                      return elem
         | 
| 207 | 
            +
                    end
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                    if elem.is_a?(::Selenium::WebDriver::Error::NoSuchElementError)
         | 
| 210 | 
            +
                      return elem
         | 
| 211 | 
            +
                    end
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                    if elem.send(options[:check_element])
         | 
| 214 | 
            +
                      return elem
         | 
| 215 | 
            +
                    end
         | 
| 216 | 
            +
                    return nil
         | 
| 217 | 
            +
                  end
         | 
| 208 218 | 
             
                end # module DriverModule
         | 
| 209 219 | 
             
              end # module MultiFind
         | 
| 210 220 | 
             
            end # module Unobtainium
         | 
| 211 221 |  | 
| 212 222 | 
             
            ::Unobtainium::Driver.register_module(
         | 
| 213 223 | 
             
                ::Unobtainium::MultiFind::DriverModule,
         | 
| 214 | 
            -
                __FILE__ | 
| 224 | 
            +
                __FILE__
         | 
| 225 | 
            +
            )
         | 
    
        data/spec/module_spec.rb
    CHANGED
    
    | @@ -38,6 +38,10 @@ describe 'Unobtainium::MultiFind::DriverModule' do | |
| 38 38 | 
             
              end
         | 
| 39 39 |  | 
| 40 40 | 
             
              describe "find functionality" do
         | 
| 41 | 
            +
                before do
         | 
| 42 | 
            +
                  require 'unobtainium-multifind'
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 41 45 | 
             
                it "can find a single element" do
         | 
| 42 46 | 
             
                  drv = @tester.driver(DRIVER)
         | 
| 43 47 | 
             
                  drv.navigate.to(TEST_URL)
         | 
| @@ -181,6 +185,10 @@ describe 'Unobtainium::MultiFind::DriverModule' do | |
| 181 185 | 
             
              end
         | 
| 182 186 |  | 
| 183 187 | 
             
              describe "find options" do
         | 
| 188 | 
            +
                before do
         | 
| 189 | 
            +
                  require 'unobtainium-multifind'
         | 
| 190 | 
            +
                end
         | 
| 191 | 
            +
             | 
| 184 192 | 
             
                it "can throw on errors" do
         | 
| 185 193 | 
             
                  drv = @tester.driver(DRIVER)
         | 
| 186 194 | 
             
                  drv.navigate.to(TEST_URL)
         | 
| @@ -252,5 +260,50 @@ describe 'Unobtainium::MultiFind::DriverModule' do | |
| 252 260 | 
             
                    drv.find(xpath: '//foo')
         | 
| 253 261 | 
             
                  end.to raise_error
         | 
| 254 262 | 
             
                end
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                it "can override the find method with :find_elements" do
         | 
| 265 | 
            +
                  drv = @tester.driver(DRIVER)
         | 
| 266 | 
            +
                  drv.navigate.to(TEST_URL)
         | 
| 267 | 
            +
             | 
| 268 | 
            +
                  drv.multifind_options = { find_method: :find_elements }
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                  elem = drv.find(xpath: '//foo/bar')
         | 
| 271 | 
            +
                  expect(elem).not_to be_nil
         | 
| 272 | 
            +
                  expect(elem).not_to be_empty
         | 
| 273 | 
            +
                  expect(elem.length).to eql 1
         | 
| 274 | 
            +
                  expect(elem[0]).not_to be_nil
         | 
| 275 | 
            +
             | 
| 276 | 
            +
                  expect(elem[0].is_a?(Array)).to be_truthy
         | 
| 277 | 
            +
                  expect(elem[0].length).to eql 1
         | 
| 278 | 
            +
                  expect(elem[0][0]).not_to be_nil
         | 
| 279 | 
            +
                end
         | 
| 280 | 
            +
             | 
| 281 | 
            +
                it "treats hidden elements well with :find_elements" do
         | 
| 282 | 
            +
                  drv = @tester.driver(DRIVER)
         | 
| 283 | 
            +
                  drv.navigate.to(TEST_URL)
         | 
| 284 | 
            +
             | 
| 285 | 
            +
                  drv.multifind_options = { find_method: :find_elements }
         | 
| 286 | 
            +
             | 
| 287 | 
            +
                  elem = drv.find(xpath: '//foo/hidden')
         | 
| 288 | 
            +
                  expect(elem).not_to be_nil
         | 
| 289 | 
            +
                  expect(elem).not_to be_empty
         | 
| 290 | 
            +
                  expect(elem.length).to eql 1
         | 
| 291 | 
            +
                  expect(elem[0]).not_to be_nil
         | 
| 292 | 
            +
             | 
| 293 | 
            +
                  expect(elem[0].is_a?(Array)).to be_truthy
         | 
| 294 | 
            +
                  expect(elem[0].length).to eql 1
         | 
| 295 | 
            +
                  expect(elem[0][0]).to be_nil
         | 
| 296 | 
            +
                end
         | 
| 297 | 
            +
             | 
| 298 | 
            +
                it "raises errors when the find method is invalid" do
         | 
| 299 | 
            +
                  drv = @tester.driver(DRIVER)
         | 
| 300 | 
            +
                  drv.navigate.to(TEST_URL)
         | 
| 301 | 
            +
             | 
| 302 | 
            +
                  drv.multifind_options = { find_method: :does_not_exist }
         | 
| 303 | 
            +
             | 
| 304 | 
            +
                  expect do
         | 
| 305 | 
            +
                    drv.find(xpath: '//foo/bar')
         | 
| 306 | 
            +
                  end.to raise_error
         | 
| 307 | 
            +
                end
         | 
| 255 308 | 
             
              end
         | 
| 256 309 | 
             
            end
         | 
| @@ -42,7 +42,7 @@ Gem::Specification.new do |spec| | |
| 42 42 | 
             
              spec.requirements  = "Unobtainium driver implementing the Selenium API"
         | 
| 43 43 |  | 
| 44 44 | 
             
              spec.add_development_dependency "bundler", "~> 1.12"
         | 
| 45 | 
            -
              spec.add_development_dependency "rubocop", "~> 0. | 
| 45 | 
            +
              spec.add_development_dependency "rubocop", "~> 0.40"
         | 
| 46 46 | 
             
              spec.add_development_dependency "rake", "~> 11.1"
         | 
| 47 47 | 
             
              spec.add_development_dependency "rspec", "~> 3.4"
         | 
| 48 48 | 
             
              spec.add_development_dependency "simplecov", "~> 0.11"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: unobtainium-multifind
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jens Finkhaeuser
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-05- | 
| 11 | 
            +
            date: 2016-05-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '0. | 
| 33 | 
            +
                    version: '0.40'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0. | 
| 40 | 
            +
                    version: '0.40'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: rake
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         |