Class: Rufus::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/rufus/driver.rb

Instance Method Summary collapse

Constructor Details

#initializeDriver

Returns a new instance of Driver.



11
12
13
14
15
# File 'lib/rufus/driver.rb', line 11

def initialize
  raise 'No config.yml found' if !File.exists?('config.yml')
  @config = YAML.load(ERB.new(File.read('config.yml')).result)
  @url = url(@config)
end

Instance Method Details

#alert_shown?Boolean

Returns:

  • (Boolean)


133
134
135
136
137
138
139
140
# File 'lib/rufus/driver.rb', line 133

def alert_shown?
  all_elements.each do |element|
    if is_alert?(element)
      return true
    end
  end
  false
end

#buttonsObject



77
78
79
80
81
82
83
84
# File 'lib/rufus/driver.rb', line 77

def buttons
  buttons = []
  elements = elements_by_tag 'UIAButton'
  elements.each do |element|
    buttons << element.text
  end
  buttons
end

#class_for(element) ⇒ Object



142
143
144
# File 'lib/rufus/driver.rb', line 142

def class_for(element)
  element.tag_name
end

#click(locator) ⇒ Object



44
45
46
# File 'lib/rufus/driver.rb', line 44

def click(locator)
  find(locator).click
end

#click_alert(button) ⇒ Object



127
128
129
130
131
# File 'lib/rufus/driver.rb', line 127

def click_alert(button)
  if alert_shown?
    click_alert_button(button)
  end
end

#configObject



26
27
28
# File 'lib/rufus/driver.rb', line 26

def config
  @config
end

#displayed?(locator) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rufus/driver.rb', line 56

def displayed?(locator)
  find(locator).displayed?
end

#enabled?(locator) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rufus/driver.rb', line 52

def enabled?(locator)
  find(locator).enabled?
end

#find(locator) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rufus/driver.rb', line 34

def find(locator)
  how = locator.keys[0].to_sym
  what = locator[how]
  begin
    driver.find_element(how, what)
  rescue Selenium::WebDriver::Error::NoSuchElementError
    return nil
  end
end

#find_alert(locator) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/rufus/driver.rb', line 117

def find_alert(locator)
  alert = nil
  all_elements.each do |element|
    if is_alert?(element)
      alert = element if match?(element, locator[:name])
    end
  end
  alert
end

#labelsObject



95
96
97
98
99
100
101
102
# File 'lib/rufus/driver.rb', line 95

def labels
  labels = []
  elements = elements_by_tag 'UIAStaticText'
  elements.each do |element|
    labels << element.text
  end
  labels
end

#match?(element, name) ⇒ Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/rufus/driver.rb', line 146

def match?(element, name)
  element.attribute(:name).eql? name
end

#orientationObject



60
61
62
# File 'lib/rufus/driver.rb', line 60

def orientation
  driver.orientation.to_s
end

#press_button(name) ⇒ Object



48
49
50
# File 'lib/rufus/driver.rb', line 48

def press_button name
  click(:name => name)
end

#quitObject



21
22
23
24
# File 'lib/rufus/driver.rb', line 21

def quit
  driver.quit
  @selenium = nil
end

#rotate(orientation) ⇒ Object



64
65
66
# File 'lib/rufus/driver.rb', line 64

def rotate(orientation)
  driver.rotate orientation
end

#sequence(*names, times) ⇒ Object



73
74
75
# File 'lib/rufus/driver.rb', line 73

def sequence(*names, times)
  timed_sequence(names, times, 1)
end

#server_urlObject



30
31
32
# File 'lib/rufus/driver.rb', line 30

def server_url
  @url
end

#startObject



17
18
19
# File 'lib/rufus/driver.rb', line 17

def start
  driver.get @url
end

#text_fieldsObject



86
87
88
89
90
91
92
93
# File 'lib/rufus/driver.rb', line 86

def text_fields
  fields = []
  elements = elements_by_tag 'UIATextField'
  elements.each do |element|
    fields << element.text
  end
  fields
end

#timed_sequence(names, times, seconds) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rufus/driver.rb', line 104

def timed_sequence(names, times, seconds)
  current = 0
  until current == times
    names.each do |name|
      click(:name => name)
      sleep seconds

    end
    current += 1
    puts "sequence #{current} completed"
  end
end

#type(keys, name) ⇒ Object



68
69
70
71
# File 'lib/rufus/driver.rb', line 68

def type(keys, name)
  locator = {:name => name}
  find(locator).send_keys keys
end