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.



9
10
11
12
13
# File 'lib/rufus/driver.rb', line 9

def initialize
  raise 'No config.yml found' if !File.exists?('config.yml')
  @config = YAML.load_file('config.yml')
  @url = url(@config)
end

Instance Method Details

#alert_shown?Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
# File 'lib/rufus/driver.rb', line 114

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

#buttonsObject



58
59
60
61
62
63
64
65
# File 'lib/rufus/driver.rb', line 58

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

#class_for(element) ⇒ Object



123
124
125
# File 'lib/rufus/driver.rb', line 123

def class_for(element)
  element.tag_name
end

#click(locator) ⇒ Object



33
34
35
# File 'lib/rufus/driver.rb', line 33

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

#click_alert(button) ⇒ Object



108
109
110
111
112
# File 'lib/rufus/driver.rb', line 108

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

#configObject



19
20
21
# File 'lib/rufus/driver.rb', line 19

def config
  @config
end

#displayed?(locator) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#enabled?(locator) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rufus/driver.rb', line 41

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

#find(locator) ⇒ Object



27
28
29
30
31
# File 'lib/rufus/driver.rb', line 27

def find(locator)
  how = locator.keys[0].to_sym
  what = locator[how]
  driver.find_element(how, what)
end

#find_alert(locator) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/rufus/driver.rb', line 98

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



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

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

#match?(element, name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#press_button(name) ⇒ Object



37
38
39
# File 'lib/rufus/driver.rb', line 37

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

#sequence(*names, times) ⇒ Object



54
55
56
# File 'lib/rufus/driver.rb', line 54

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

#server_urlObject



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

def server_url
  @url
end

#startObject



15
16
17
# File 'lib/rufus/driver.rb', line 15

def start
  driver.get @url
end

#text_fieldsObject



67
68
69
70
71
72
73
74
# File 'lib/rufus/driver.rb', line 67

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



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

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



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

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