Class: Mdq::DB
Overview
DB
Instance Method Summary collapse
-
#app_install(input, udid, is_replace) ⇒ Object
Appをインストールする.
-
#app_uninstall(input, udid) ⇒ Object
Appをアンインストールする.
-
#device_screencap(output, udid = nil) ⇒ Object
Androidデバイスのスクリーンショットを撮る.
-
#get(is_android: true, is_apple: true, is_apps: true) ⇒ Object
デバイスとアプリの取得.
-
#query(sql) ⇒ Object
クエリの実行.
- #sim_screencap(output, is_android: true) ⇒ Object
Methods inherited from Discovery
#android_discoverable?, #apple_discoverable?, #initialize
Constructor Details
This class inherits a constructor from Mdq::Discovery
Instance Method Details
#app_install(input, udid, is_replace) ⇒ Object
Appをインストールする
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mdq/db.rb', line 80 def app_install(input, udid, is_replace) device = Device.find_by(udid: udid) if device.nil? warn 'Device not found.' return end if device.android? if is_replace output, error = adb_command("install -r #{input}", udid) else output, error = adb_command("install #{input}", udid) end else output, error = apple_command("device install app #{input}", udid) end puts output unless output.empty? warn error unless error.empty? end |
#app_uninstall(input, udid) ⇒ Object
Appをアンインストールする
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mdq/db.rb', line 102 def app_uninstall(input, udid) device = Device.find_by(udid: udid) if device.nil? warn 'Device not found.' return end if device.android? output, error = adb_command("uninstall #{input}", udid) else output, error = apple_command("device uninstall app #{input}", udid) end puts output unless output.empty? warn error unless error.empty? end |
#device_screencap(output, udid = nil) ⇒ Object
Androidデバイスのスクリーンショットを撮る
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mdq/db.rb', line 38 def device_screencap(output, udid = nil) devices = if udid.nil? Device.where(physical: true) else Device .where('udid LIKE ?', "#{udid}%") .where(physical: true) end if devices.empty? warn 'Device not found.' return end FileUtils.mkdir_p(output) devices.each do |device| file = "#{device.udid}-#{Time.now.strftime('%y%m%d-%H%M%S')}.png" if device.android? full_path = "/sdcard/#{file}" adb_command("shell screencap -p #{full_path}", device.udid) adb_command("pull #{full_path} #{output}", device.udid) adb_command("shell rm #{full_path}", device.udid) else apple_command("device capture screenshot --destination #{output}/#{file}", device.udid) end end end |
#get(is_android: true, is_apple: true, is_apps: true) ⇒ Object
デバイスとアプリの取得
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mdq/db.rb', line 12 def get(is_android: true, is_apple: true, is_apps: true) reset # デバイスの発見 android_discover if is_android apple_discover if is_apple return unless is_apps Device.all.each do |model| # インストール済みAppの取得 if model.android? android_apps(model.udid) else apple_apps(model.udid) end end end |
#query(sql) ⇒ Object
クエリの実行
31 32 33 34 35 |
# File 'lib/mdq/db.rb', line 31 def query(sql) ActiveRecord::Base.connection.execute(sql) rescue StandardError [] end |
#sim_screencap(output, is_android: true) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mdq/db.rb', line 68 def sim_screencap(output, is_android: true) if is_android output, error = adb_command("emu screenrecord #{output}}") else output, error = apple_sim_command("io booted screenshot #{output}") end puts output unless output.empty? warn error unless error.empty? end |