Class: Cukunity::IOS::UIAutomation
- Inherits:
-
Object
- Object
- Cukunity::IOS::UIAutomation
- Defined in:
- lib/cukunity/drivers/iOS/uiautomation.rb
Constant Summary
Constants included from Utils
Cukunity::IOS::Utils::MOBILE_DEVICE_DEFAULT_TIMEOUT
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ UIAutomation
constructor
A new instance of UIAutomation.
- #popen(bundle_id) ⇒ Object
Methods included from Utils
#check_timeout, #merge_options, #restrict_options, #to_options, #wait_connectivity
Methods included from Utils
#bundle_identifier, #device_udid, #mobile_device_cmd, #uiautomation_cmd, #unity_command
Constructor Details
#initialize ⇒ UIAutomation
Returns a new instance of UIAutomation.
10 11 12 13 14 |
# File 'lib/cukunity/drivers/iOS/uiautomation.rb', line 10 def initialize @pipe = nil @tmpdir = [] @pipes = [] end |
Instance Method Details
#close ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cukunity/drivers/iOS/uiautomation.rb', line 67 def close # close all created pipes @pipes.each do |pipe| ::Process.kill('KILL', pipe.pid) rescue ::Exception pipe.close rescue ::Exception end @pipes = [] # remove all created temporary dirs @tmpdir.each do |tmpdir| FileUtils.remove_entry_secure(tmpdir, true) end @tmpdir = [] end |
#popen(bundle_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 |
# File 'lib/cukunity/drivers/iOS/uiautomation.rb', line 16 def popen(bundle_id) udid = device_udid # create a temp directory for instrument logs and js file tmpdir = File.(Dir.mktmpdir(['cukunity_', '_uiautomation'])) cmd = nil begin # export javascript to folder too slave_js = File.join(tmpdir, 'uiautomation_slave.js') slave_rb = File.join(File.dirname(__FILE__), 'uiautomation_slave.rb') slave_js_opts = { :ruby => File.(RbConfig.ruby), :slave => slave_rb, :address => UIAutomationMaster.instance.address, :port => UIAutomationMaster.instance.port, :bundle_id => bundle_id } generate_slave_js(slave_js, slave_js_opts) # as of Xcode 4.3.2, the Developer folder is now in a different place. templates = [ '/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate', '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate' ] template = templates.find do |template| File.file?(template) end # build path to command cmd = ['instruments', '-w', udid, '-t', template, bundle_id, '-e', 'UIASCRIPT', slave_js, '-e', 'UIARESULTSPATH', tmpdir, :err => [:child, :out]] rescue => err FileUtils.remove_entry_secure(tmpdir) raise err end # remove later @tmpdir << tmpdir # execute UIAutomation instruments Dir.chdir tmpdir do @pipes << IO.popen(cmd) end end |