Module: Calabash::Cucumber::UIA

Included in:
Core
Defined in:
lib/calabash-cucumber/uia.rb

Instance Method Summary collapse

Instance Method Details

#escape_uia_string(string) ⇒ Object



97
98
99
100
# File 'lib/calabash-cucumber/uia.rb', line 97

def escape_uia_string(string)
  #TODO escape '\n in query
  string
end

#send_uia_command(opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/calabash-cucumber/uia.rb', line 8

def send_uia_command(opts ={})
  run_loop = opts[:run_loop] || (@calabash_launcher && @calabash_launcher.active? && @calabash_launcher.run_loop)
  command = opts[:command]
  raise ArgumentError, 'please supply :run_loop or instance var @calabash_launcher' unless run_loop
  raise ArgumentError, 'please supply :command' unless command
  RunLoop.send_command(run_loop, opts[:command])
end

#uia_element_does_not_exist?(*queryparts) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/calabash-cucumber/uia.rb', line 46

def uia_element_does_not_exist?(*queryparts)
  uia_handle_command(:elementDoesNotExist, queryparts)
end

#uia_element_exists?(*queryparts) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/calabash-cucumber/uia.rb', line 42

def uia_element_exists?(*queryparts)
  uia_handle_command(:elementExists, queryparts)
end

#uia_enterObject



58
59
60
# File 'lib/calabash-cucumber/uia.rb', line 58

def uia_enter()
  uia_handle_command(:enter)
end

#uia_handle_command(cmd, *query_args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/calabash-cucumber/uia.rb', line 72

def uia_handle_command(cmd, *query_args)
  args = query_args.map do |part|
    if part.is_a?(String)
      "'#{escape_uia_string(part)}'"
    else
      "'#{escape_uia_string(part.to_edn)}'"
    end
  end
  command = %Q[uia.#{cmd}(#{args.join(', ')})]
  if ENV['DEBUG'] == '1'
    puts "Sending UIA command"
    puts command
  end
  s=send_uia_command :command => command
  if ENV['DEBUG'] == '1'
    puts "Result"
    p s
  end
  if s['status'] == 'success'
    s['value']
  else
    raise s
  end
end

#uia_names(*queryparts) ⇒ Object



21
22
23
24
# File 'lib/calabash-cucumber/uia.rb', line 21

def uia_names(*queryparts)
  #TODO escape '\n etc in query
  uia_handle_command(:names, queryparts)
end

#uia_pan(from_q, to_q) ⇒ Object



34
35
36
# File 'lib/calabash-cucumber/uia.rb', line 34

def uia_pan(from_q, to_q)
  uia_handle_command(:pan, from_q, to_q)
end

#uia_query(*queryparts) ⇒ Object



16
17
18
19
# File 'lib/calabash-cucumber/uia.rb', line 16

def uia_query(*queryparts)
  #TODO escape '\n etc in query
  uia_handle_command(:query, queryparts)
end

#uia_screenshot(name) ⇒ Object



50
51
52
# File 'lib/calabash-cucumber/uia.rb', line 50

def uia_screenshot(name)
  uia_handle_command(:elementDoesNotExist, name)
end

#uia_scroll_to(*queryparts) ⇒ Object



38
39
40
# File 'lib/calabash-cucumber/uia.rb', line 38

def uia_scroll_to(*queryparts)
  uia_handle_command(:scrollTo, queryparts)
end

#uia_set_location(place) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/calabash-cucumber/uia.rb', line 62

def uia_set_location(place)
  if place.is_a?(String)
    loc = LocationOne::Client.location_by_place(place)
    loc_data = {"latitude"=>loc.latitude, "longitude"=>loc.longitude}
  else
    loc_data = place
  end
  uia_handle_command(:setLocation, loc_data)
end

#uia_tap(*queryparts) ⇒ Object



26
27
28
# File 'lib/calabash-cucumber/uia.rb', line 26

def uia_tap(*queryparts)
  uia_handle_command(:tap, queryparts)
end

#uia_tap_mark(mark) ⇒ Object



30
31
32
# File 'lib/calabash-cucumber/uia.rb', line 30

def uia_tap_mark(mark)
  uia_handle_command(:tapMark, mark)
end

#uia_type_string(string) ⇒ Object



54
55
56
# File 'lib/calabash-cucumber/uia.rb', line 54

def uia_type_string(string)
  uia_handle_command(:typeString, string)
end