Module: Calabash::Android::Operations

Defined in:
lib/calabash-android/operations.rb

Defined Under Namespace

Classes: Device

Instance Method Summary collapse

Instance Method Details

#app_to_background(secs) ⇒ Object



450
451
452
# File 'lib/calabash-android/operations.rb', line 450

def app_to_background(secs)
  ni
end

#backdoor(sel, arg) ⇒ Object



504
505
506
# File 'lib/calabash-android/operations.rb', line 504

def backdoor(sel, arg)
  ni
end

#cell_swipe(options = {}) ⇒ Object



426
427
428
# File 'lib/calabash-android/operations.rb', line 426

def cell_swipe(options={})
  ni
end

#check_element_does_not_exist(query) ⇒ Object



468
469
470
471
472
# File 'lib/calabash-android/operations.rb', line 468

def check_element_does_not_exist( query )
  if element_exists( query )
    screenshot_and_raise "Expected no elements to match query: #{query}"
  end
end

#check_element_exists(query) ⇒ Object



462
463
464
465
466
# File 'lib/calabash-android/operations.rb', line 462

def check_element_exists( query )
  if not element_exists( query )
    screenshot_and_raise "No element found for query: #{query}"
  end
end

#check_view_with_mark_exists(expected_mark) ⇒ Object



474
475
476
# File 'lib/calabash-android/operations.rb', line 474

def check_view_with_mark_exists(expected_mark)
  check_element_exists( "view marked:'#{expected_mark}'" )
end

#clear_app_dataObject



56
57
58
# File 'lib/calabash-android/operations.rb', line 56

def clear_app_data
  default_device.clear_app_data
end

#connect_to_test_serverObject

app life cycle



121
122
123
124
125
# File 'lib/calabash-android/operations.rb', line 121

def connect_to_test_server
  puts "Explicit calls to connect_to_test_server should be removed."
  puts "Please take a look in your hooks file for calls to this methods."
  puts "(Hooks are stored in features/support)"
end

#default_deviceObject



32
33
34
35
36
37
# File 'lib/calabash-android/operations.rb', line 32

def default_device
  unless @default_device
    @default_device = Device.new(self, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
  end
  @default_device
end

#disconnect_from_test_serverObject



127
128
129
130
131
# File 'lib/calabash-android/operations.rb', line 127

def disconnect_from_test_server
  puts "Explicit calls to disconnect_from_test_server should be removed."
  puts "Please take a look in your hooks file for calls to this methods."
  puts "(Hooks are stored in features/support)"
end

#doneObject



430
431
432
# File 'lib/calabash-android/operations.rb', line 430

def done
  ni
end

#element_exists(uiquery) ⇒ Object



454
455
456
# File 'lib/calabash-android/operations.rb', line 454

def element_exists(uiquery)
  !query(uiquery).empty?
end

#element_is_not_hidden(uiquery) ⇒ Object

a better name would be element_exists_and_is_not_hidden



479
480
481
# File 'lib/calabash-android/operations.rb', line 479

def element_is_not_hidden(uiquery)
   ni
end

#html(q) ⇒ Object



405
406
407
# File 'lib/calabash-android/operations.rb', line 405

def html(q)
  query(q).map {|e| e['html']}
end

#http(options, data = nil) ⇒ Object



401
402
403
# File 'lib/calabash-android/operations.rb', line 401

def http(options, data=nil)
  default_device.http(options, data)
end

#install_app(app_path) ⇒ Object



43
44
45
# File 'lib/calabash-android/operations.rb', line 43

def install_app(app_path)
  default_device.install_app(app_path)
end

#interpolate(recording, options = {}) ⇒ Object



492
493
494
# File 'lib/calabash-android/operations.rb', line 492

def interpolate(recording, options={})
  ni
end

#label(uiquery) ⇒ Object



376
377
378
# File 'lib/calabash-android/operations.rb', line 376

def label(uiquery)
  ni
end

#load_playback_data(recording, options = {}) ⇒ Object



484
485
486
# File 'lib/calabash-android/operations.rb', line 484

def load_playback_data(recording,options={})
  ni
end

#log(message) ⇒ Object



17
18
19
# File 'lib/calabash-android/operations.rb', line 17

def log(message)
  $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
end

#macro(txt) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/calabash-android/operations.rb', line 25

def macro(txt)
  if self.respond_to?:step
    step(txt)
  else
    Then(txt)
  end
end

#make_http_request(url, req) ⇒ Object



516
517
518
# File 'lib/calabash-android/operations.rb', line 516

def make_http_request( url, req )
  ni
end

#map(query, method_name, *method_args) ⇒ Object



508
509
510
# File 'lib/calabash-android/operations.rb', line 508

def map( query, method_name, *method_args )
  ni
end

#niObject



114
115
116
# File 'lib/calabash-android/operations.rb', line 114

def ni
  raise "Not yet implemented."
end

#performAction(action, *arguments) ⇒ Object



39
40
41
# File 'lib/calabash-android/operations.rb', line 39

def performAction(action, *arguments)
  default_device.perform_action(action, *arguments)
end

#pinch(in_out, options = {}) ⇒ Object



442
443
444
# File 'lib/calabash-android/operations.rb', line 442

def pinch(in_out,options={})
  ni
end

#playback(recording, options = {}) ⇒ Object



488
489
490
# File 'lib/calabash-android/operations.rb', line 488

def playback(recording, options={})
  ni
end

#query(uiquery, *args) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/calabash-android/operations.rb', line 97

def query(uiquery, *args)
  if uiquery.start_with? "webView"
    uiquery.slice!(0, "webView".length)
    if uiquery =~ /(css|xpath):\s*(.*)/
      r = performAction("query", $1, $2)
      JSON.parse(r["message"])
    else
     raise "Invalid query #{uiquery}"
    end
  else
    arguments = [*args]
    operation = {"method_name"=>"query", "arguments" => arguments}
    data = {"query" => uiquery, "operation" => operation}
    JSON.parse(http("/map",data))
  end
end

#record_beginObject



496
497
498
# File 'lib/calabash-android/operations.rb', line 496

def record_begin
  ni
end

#record_end(file_name) ⇒ Object



500
501
502
# File 'lib/calabash-android/operations.rb', line 500

def record_end(file_name)
  ni
end

#rotate(dir) ⇒ Object



446
447
448
# File 'lib/calabash-android/operations.rb', line 446

def rotate(dir)
  ni
end

#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object



73
74
75
# File 'lib/calabash-android/operations.rb', line 73

def screenshot(options={:prefix => nil, :name => nil})
  default_device.screenshot(options)
end

#screenshot_and_raise(msg) ⇒ Object



380
381
382
383
384
# File 'lib/calabash-android/operations.rb', line 380

def screenshot_and_raise(msg)
  screenshot_embed
  sleep 5
  raise(msg)
end

#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object



68
69
70
71
# File 'lib/calabash-android/operations.rb', line 68

def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
  path = default_device.screenshot(options)
  embed(path, "image/png", options[:label] || File.basename(path))
end

#scroll(uiquery, direction) ⇒ Object



434
435
436
# File 'lib/calabash-android/operations.rb', line 434

def scroll(uiquery,direction)
  ni
end

#scroll_to_row(uiquery, number) ⇒ Object



438
439
440
# File 'lib/calabash-android/operations.rb', line 438

def scroll_to_row(uiquery,number)
  ni
end

#set_gps_coordinates(latitude, longitude) ⇒ Object



81
82
83
# File 'lib/calabash-android/operations.rb', line 81

def set_gps_coordinates(latitude, longitude)
  default_device.set_gps_coordinates(latitude, longitude)
end

#set_gps_coordinates_from_location(location) ⇒ Object



77
78
79
# File 'lib/calabash-android/operations.rb', line 77

def set_gps_coordinates_from_location(location)
  default_device.set_gps_coordinates_from_location(location)
end

#set_text(uiquery, txt) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
# File 'lib/calabash-android/operations.rb', line 409

def set_text(uiquery, txt)
  raise "Currently queries are only supported for webviews" unless uiquery.start_with? "webView"

  uiquery.slice!(0, "webView".length)
  if uiquery =~ /(css|xpath):\s*(.*)/
    r = performAction("set_text", $1, $2, txt)
    JSON.parse(r["message"])
  else
   raise "Invalid query #{uiquery}"
  end
end

#shutdown_test_serverObject



64
65
66
# File 'lib/calabash-android/operations.rb', line 64

def shutdown_test_server
  default_device.shutdown_test_server
end

#start_test_server_in_backgroundObject



60
61
62
# File 'lib/calabash-android/operations.rb', line 60

def start_test_server_in_background
  default_device.start_test_server_in_background()
end

#swipe(dir, options = {}) ⇒ Object



422
423
424
# File 'lib/calabash-android/operations.rb', line 422

def swipe(dir,options={})
    ni
end

#take_screenshotObject



21
22
23
# File 'lib/calabash-android/operations.rb', line 21

def take_screenshot
  default_device.take_screenshot
end

#touch(uiquery, *args) ⇒ Object



386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/calabash-android/operations.rb', line 386

def touch(uiquery,*args)
  if uiquery.instance_of? String
    elements = query(uiquery, *args)
    raise "No elements found" if elements.empty?
    element = elements.first
  else
    element = uiquery
  end


  center_x = element["frame"]["x"] + element["frame"]["width"] / 2
  center_y = element["frame"]["y"] + element["frame"]["height"] / 2
  performAction("touch_coordinate", center_x, center_y)
end

#uninstall_appsObject



47
48
49
50
# File 'lib/calabash-android/operations.rb', line 47

def uninstall_apps
  default_device.uninstall_app("sh.calaba.android.test")
  default_device.uninstall_app(ENV["PACKAGE_NAME"])
end

#url_for(verb) ⇒ Object



512
513
514
# File 'lib/calabash-android/operations.rb', line 512

def url_for( verb )
  ni
end

#view_with_mark_exists(expected_mark) ⇒ Object



458
459
460
# File 'lib/calabash-android/operations.rb', line 458

def view_with_mark_exists(expected_mark)
  element_exists( "view marked:'#{expected_mark}'" )
end

#wait_for(timeout, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/calabash-android/operations.rb', line 85

def wait_for(timeout, &block)
  begin
    Timeout::timeout(timeout) do
      until block.call
        sleep 0.3
      end
    end
  rescue Exception => e
    raise e
  end
end

#wake_upObject



52
53
54
# File 'lib/calabash-android/operations.rb', line 52

def wake_up
  default_device.wake_up()
end