Sha256: a46e6d19e6d6463a0df5985f730ca3a7a3681b62302a0eb77d6e3e56c6b91c1b

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

module Webdrone
  class Browser
    def vrfy
      @vrfy ||= Vrfy.new self
    end
  end

  class Vrfy
    attr_accessor :a0

    def initialize(a0)
      @a0 = a0
    end

    def vrfy(text, n: 1, all: false, visible: true, attr: nil, eq: nil, contains: nil)
      item = @a0.find.send __callee__, text, n: n, all: all, visible: visible
      if item.is_a? Array
        item.each { |x| vrfy_item x, attr: attr, eq: eq, contains: contains }
      else
        vrfy_item item, attr: attr, eq: eq, contains: contains
      end
    end

    def vrfy_item(item, attr: nil, eq: nil, contains: nil)
      if attr != nil
        r = item.attribute(attr) == eq if eq != nil
        r = item.attribute(attr).include? contains if contains != nil
      elsif eq != nil
        r = item.text == eq
      elsif contains != nil
        r = item.text.include? contains
      end
      if r == false
        targ = "eq: [#{eq}]" if eq
        targ = "contains: [#{contains}]" if contains
        if attr != nil
          raise Exception.new "ERROR: Attribute [#{attr}] value [#{item.attribute(attr)}] does not comply #{targ}"
        else
          raise Exception.new "ERROR: Value [#{item.text}] does not comply #{targ}"
        end
      end
    end

    alias_method :id,     :vrfy
    alias_method :css,    :vrfy
    alias_method :link,   :vrfy
    alias_method :button, :vrfy
    alias_method :on,     :vrfy
    alias_method :option, :vrfy
    alias_method :xpath,  :vrfy

    protected :vrfy, :vrfy_item
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webdrone-1.0.8 lib/webdrone/vrfy.rb
webdrone-1.0.6 lib/webdrone/vrfy.rb
webdrone-1.0.4 lib/webdrone/vrfy.rb
webdrone-1.0.0 lib/webdrone/vrfy.rb
webdrone-0.9.9 lib/webdrone/vrfy.rb