Class: Rufus::Driver
- Inherits:
-
Object
- Object
- Rufus::Driver
- Defined in:
- lib/rufus/driver.rb
Instance Method Summary collapse
- #alert_shown? ⇒ Boolean
- #buttons ⇒ Object
- #class_for(element) ⇒ Object
- #click(locator) ⇒ Object
- #click_alert(button) ⇒ Object
- #config ⇒ Object
- #displayed?(locator) ⇒ Boolean
- #enabled?(locator) ⇒ Boolean
- #find(locator) ⇒ Object
- #find_alert(locator) ⇒ Object
-
#initialize ⇒ Driver
constructor
A new instance of Driver.
- #labels ⇒ Object
- #match?(element, name) ⇒ Boolean
- #orientation ⇒ Object
- #press_button(name) ⇒ Object
- #quit ⇒ Object
- #rotate(orientation) ⇒ Object
- #sequence(*names, times) ⇒ Object
- #server_url ⇒ Object
- #start ⇒ Object
- #text_fields ⇒ Object
- #timed_sequence(names, times, seconds) ⇒ Object
- #type(keys, name) ⇒ Object
Constructor Details
#initialize ⇒ Driver
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
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 |
#buttons ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/rufus/driver.rb', line 77 def = [] elements = elements_by_tag 'UIAButton' elements.each do |element| << element.text end 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() if alert_shown? () end end |
#config ⇒ Object
26 27 28 |
# File 'lib/rufus/driver.rb', line 26 def config @config end |
#displayed?(locator) ⇒ Boolean
56 57 58 |
# File 'lib/rufus/driver.rb', line 56 def displayed?(locator) find(locator).displayed? end |
#enabled?(locator) ⇒ 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 |
#labels ⇒ Object
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
146 147 148 |
# File 'lib/rufus/driver.rb', line 146 def match?(element, name) element.attribute(:name).eql? name end |
#orientation ⇒ Object
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 name click(:name => name) end |
#quit ⇒ Object
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_url ⇒ Object
30 31 32 |
# File 'lib/rufus/driver.rb', line 30 def server_url @url end |
#start ⇒ Object
17 18 19 |
# File 'lib/rufus/driver.rb', line 17 def start driver.get @url end |
#text_fields ⇒ Object
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 |