Class: Hive::Worker::Ios
- Inherits:
-
Hive::Worker
- Object
- Hive::Worker
- Hive::Worker::Ios
- Defined in:
- lib/hive/worker/ios.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
Instance Method Summary collapse
-
#after_error(job, file_system, script) ⇒ Object
Take screenshot when there is an error.
- #alter_project(project_path) ⇒ Object
-
#autogenerated_queues ⇒ Object
def device_status.
- #hive_mind_device_identifiers ⇒ Object
-
#initialize(device) ⇒ Ios
constructor
A new instance of Ios.
- #job_message_klass ⇒ Object
- #post_script(job, file_system, script) ⇒ Object
- #pre_script(job, file_system, script) ⇒ Object
- #replace_project_data(options = {}) ⇒ Object
Constructor Details
#initialize(device) ⇒ Ios
Returns a new instance of Ios.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hive/worker/ios.rb', line 24 def initialize(device) @serial = device['serial'] @queue_prefix = device['queue_prefix'].to_s == '' ? '' : "#{device['queue_prefix']}-" @model = device['model'].downcase.gsub(/\s/, '_') @device_range = device['device_range'].downcase @os_version = device['os_version'] @worker_ports = PortReserver.new @device_api = DeviceAPI::IOS.device(@serial) device["device_api"] = @device_api set_device_status('happy') self.device = device super(device) end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
22 23 24 |
# File 'lib/hive/worker/ios.rb', line 22 def device @device end |
Instance Method Details
#after_error(job, file_system, script) ⇒ Object
Take screenshot when there is an error
163 164 165 166 |
# File 'lib/hive/worker/ios.rb', line 163 def after_error(job, file_system, script) @log.info('Taking screenshot after error') @device_api.screenshot(filename: File.('error.tiff', file_system.results_path)) end |
#alter_project(project_path) ⇒ Object
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 |
# File 'lib/hive/worker/ios.rb', line 38 def alter_project(project_path) dev_team = @options['development_team'] || '' signing_identity = @options['signing_identity'] || '' provisioning_profile = @options['provisioning_profile'] || '' helper = FruityBuilder::IOS::Helper.new(project_path) # Check to see if a project has been passed in return unless helper.has_project? @log.debug("Resign: #{job.resign}") if job.resign @log.debug("Resign: Changing bundle id to #{@options['bundle_id']}") helper.build.replace_bundle_id(@options['bundle_id']) @log.debug("Resign: Changing dev team to #{dev_team}") helper.build.replace_dev_team(dev_team) @log.debug("Resign: Changing signing identity to #{signing_identity}") helper.build.replace_code_sign_identity(signing_identity) @log.debug("Resign: Changing provisioning profile to #{provisioning_profile}") helper.build.replace_provisioning_profile(provisioning_profile) helper.build.save_project_properties @log.debug("Finished resigning") end end |
#autogenerated_queues ⇒ Object
def device_status
end
def set_device_status(status)
end
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/hive/worker/ios.rb', line 176 def autogenerated_queues [ "#{@queue_prefix}#{@model}", "#{@queue_prefix}ios", "#{@queue_prefix}ios-#{@os_version}", "#{@queue_prefix}ios-#{@os_version}-#{@model}", "#{@queue_prefix}#{@device_range}", "#{@queue_prefix}#{@device_range}-#{@os_version}" ] end |
#hive_mind_device_identifiers ⇒ Object
187 188 189 190 191 192 |
# File 'lib/hive/worker/ios.rb', line 187 def hive_mind_device_identifiers { serial: @serial, device_type: 'Mobile' } end |
#job_message_klass ⇒ Object
137 138 139 |
# File 'lib/hive/worker/ios.rb', line 137 def Hive::Messages::IosJob end |
#post_script(job, file_system, script) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/hive/worker/ios.rb', line 141 def post_script(job, file_system, script) @log.info('Post script') @worker_ports.ports.each do |name, port| @port_allocator.release_port(port) end @installed_apps_after = @device_api.list_installed_packages @log.debug("Apps installed after test:") @installed_apps_after.each_pair do |app, details| @log.debug(" #{app}") details.each_pair do |k, v| @log.debug(" #{k}: #{v}") end end (@installed_apps_after.keys - @installed_apps.keys).each do |app| @log.info("Uninstalling #{app} (#{@installed_apps_after[app][:package_name]})") @device_api.uninstall(@installed_apps_after[app][:package_name]) end set_device_status('happy') end |
#pre_script(job, file_system, script) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/hive/worker/ios.rb', line 76 def pre_script(job, file_system, script) set_device_status('busy') @installed_apps = @device_api.list_installed_packages @log.debug("Apps installed before test:") @installed_apps.each_pair do |app, details| @log.debug(" #{app}") details.each_pair do |k, v| @log.debug(" #{k}: #{v}") end end if job.build FileUtils.mkdir(file_system.home_path + '/build') app_path = file_system.home_path + '/build/' + 'build.ipa' file_system.fetch_build(job.build, app_path) @log.debug("Resign: #{job.resign}") if job.resign entitlements = FruityBuilder::IOS::Signing.enable_get_tasks(app_path) FruityBuilder::IOS::Signing.sign_app({ cert: @options['signing_identity'], entitlements: entitlements, app: app_path } ) app_info = FruityBuilder::IOS::Plistutil.get_bundle_id_from_app(app_path) app_bundle = app_info['CFBundleIdentifier'] @device_api.install(app_path) if job.install_build script.set_env 'BUNDLE_ID', app_bundle end else alter_project(file_system.home_path + '/test_code/code/') end ip_address = DeviceAPI::IOS::IPAddress.address(self.device['serial']) if ip_address.nil? # There is a bug in the IPAddress app that stopping the IP address from being # returned when it's first run, however it works the second time around. # This is a *temporary* fix until that issue can be resolved. ip_address = DeviceAPI::IOS::IPAddress.address(self.device['serial']) end script.set_env 'CHARLES_PROXY_PORT', @worker_ports.reserve(queue_name: 'Charles') { @port_allocator.allocate_port } # TODO: Allow the scheduler to specify the ports to use script.set_env 'APPIUM_PORT', @worker_ports.reserve(queue_name: 'Appium') { @port_allocator.allocate_port } script.set_env 'BOOTSTRAP_PORT', @worker_ports.reserve(queue_name: 'Bootstrap') { @port_allocator.allocate_port } script.set_env 'CHROMEDRIVER_PORT', @worker_ports.reserve(queue_name: 'Chromedriver') { @port_allocator.allocate_port } script.set_env 'APP_PATH', app_path script.set_env 'APP_BUNDLE_PATH', app_path script.set_env 'DEVICE_TARGET', self.device['serial'] # Required for Calabash testing script.set_env 'DEVICE_ENDPOINT', "http://#{ip_address}:37265" unless ip_address.nil? # Required for Appium testing script.set_env 'DEVICE_NAME', @device_api.name script.set_env 'PLATFORM_NAME', 'iOS' script.set_env 'PLATFORM_VERSION', @device_api.version "#{self.device['serial']} #{@worker_ports.ports['Appium']} #{app_path} #{file_system.results_path}" end |
#replace_project_data(options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hive/worker/ios.rb', line 64 def replace_project_data( = {}) regex = Regexp.new([:regex]) replacements = [:data].scan(regex).uniq.flatten result = [:data] replacements.each do |to_replace| result = result.gsub(to_replace, [:new_value]) end result end |