Class: Oats::Locator

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/oats/oats_selenium_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locator, ehow = nil) ⇒ Locator

Returns a new instance of Locator.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oats/oats_selenium_api.rb', line 23

def initialize(locator, ehow=nil)
  if locator.instance_of?(Array)
    @ehow = locator[1]
    @what = locator[0]
  elsif locator.instance_of?(String)
    @what = @locator = locator
    if ehow
      @ehow = ehow
    else
      if locator[0,5] == 'link='
        @what = locator[5..-1]
        @ehow = :link
      elsif locator[0,5] == 'name='
        @what = locator[5..-1]
        @ehow = :name
      elsif locator[0,3] == 'id='
        @what = locator[3..-1]
        @ehow = :id
      elsif locator.index('/')
        @ehow = :xpath
      else
        @ehow = :name
      end
    end
  else
    raise('Unexpected arguments')
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object

Allow “link=Accounts”.locator.wait.click



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oats/oats_selenium_api.rb', line 74

def method_missing(id,*args)
  case id
  when :wait then id = :wait_for_element
  end
  #        if selenium.webdriver?
  @element ||= selenium.element?(self)
  if @element.respond_to?(id)
    @element.send(id, *args)
  else
    raise "#{@element} has no method #{id.inspect}"
  end
  #        else
  #          if selenium.respond_to?(id)
  #            selenium.send(id,self, *args)
  #          else
  #            raise "#{selenium} has no method #{id.inspect}"
  #          end
  #        end
end

Instance Attribute Details

#ehowObject (readonly)

Returns the value of attribute ehow.



22
23
24
# File 'lib/oats/oats_selenium_api.rb', line 22

def ehow
  @ehow
end

#elementObject

Returns the value of attribute element.



21
22
23
# File 'lib/oats/oats_selenium_api.rb', line 21

def element
  @element
end

#locatorObject (readonly)

Returns the value of attribute locator.



22
23
24
# File 'lib/oats/oats_selenium_api.rb', line 22

def locator
  @locator
end

#whatObject (readonly)

Returns the value of attribute what.



22
23
24
# File 'lib/oats/oats_selenium_api.rb', line 22

def what
  @what
end

Instance Method Details

#<=>(locator) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oats/oats_selenium_api.rb', line 57

def <=>(locator)
  if locator.instance_of?(String)
    self.what <=> locator
  else
    if self.what == locator.what
      self.ehow <=> locator.ehow
    else
      self.what <=> locator.what
    end
  end
end

#===(locator) ⇒ Object



69
70
71
# File 'lib/oats/oats_selenium_api.rb', line 69

def ===(locator)
  self == locator
end

#to_sObject



52
53
54
# File 'lib/oats/oats_selenium_api.rb', line 52

def to_s
  @ehow.to_s + '='+ @what.to_s
end