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.



7
8
9
10
11
12
13
14
15
16
# File 'lib/rufus/driver.rb', line 7

def initialize
  @config = YAML.load_file('config.yml') unless !File.exists?('config.yml')

  if @config["appium_url"].nil? || @config["appium_url"].eql?("")
    @url = 'http://127.0.0.1:4723/wd/hub'
  else
    @url = @config["appium_url"]
  end

end

Instance Method Details

#buttonsObject



61
62
63
64
65
66
67
68
# File 'lib/rufus/driver.rb', line 61

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

#click(locator) ⇒ Object



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

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

#configObject



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

def config
  @config
end

#displayed?(locator) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#enabled?(locator) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#find(locator) ⇒ Object



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

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

#labelsObject



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

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

#press_button(name) ⇒ Object



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

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

#sequence(*names, times) ⇒ Object



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

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

#server_urlObject



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

def server_url
  @url
end

#startObject



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

def start
  driver.get @url
end

#text_fieldsObject



70
71
72
73
74
75
76
77
# File 'lib/rufus/driver.rb', line 70

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



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rufus/driver.rb', line 88

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



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

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