Module: RunLoop
- Defined in:
- lib/run_loop/cli.rb,
lib/run_loop/core.rb,
lib/run_loop/device.rb,
lib/run_loop/version.rb,
lib/run_loop/xctools.rb,
lib/run_loop/plist_buddy.rb,
lib/run_loop/sim_control.rb
Defined Under Namespace
Modules: Core
Classes: CLI, Device, PlistBuddy, SimControl, TimeoutError, Version, XCTools
Constant Summary
collapse
- VERSION =
'1.0.4'
Class Method Summary
collapse
Class Method Details
.default_script_for_uia_strategy(uia_strategy) ⇒ Object
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/run_loop/core.rb', line 629
def self.default_script_for_uia_strategy(uia_strategy)
case uia_strategy
when :preferences
Core.script_for_key(:run_loop_fast_uia)
when :host
Core.script_for_key(:run_loop_host)
else
Core.script_for_key(:run_loop_basic)
end
end
|
.run(options = {}) ⇒ Object
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
# File 'lib/run_loop/core.rb', line 640
def self.run(options={})
uia_strategy = options[:uia_strategy]
if options[:script]
script = validate_script(options[:script])
else
if uia_strategy
script = default_script_for_uia_strategy(uia_strategy)
else
if options[:calabash_lite]
uia_strategy = :host
script = Core.script_for_key(:run_loop_host)
else
uia_strategy = :preferences
script = default_script_for_uia_strategy(uia_strategy)
end
end
end
unless uia_strategy
desired_script = options[:script]
if desired_script.is_a?(String) uia_strategy = :host
elsif desired_script == :run_loop_host
uia_strategy = :host
elsif desired_script == :run_loop_fast_uia
uia_strategy = :preferences
else
raise "Inconsistent state: desired script #{desired_script} has not uia_strategy"
end
end
options[:script] = script
options[:uia_strategy] = uia_strategy
Core.run_with_options(options)
end
|
.send_command(run_loop, cmd, timeout = 60) ⇒ Object
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
# File 'lib/run_loop/core.rb', line 678
def self.send_command(run_loop, cmd, timeout=60)
if not cmd.is_a?(String)
raise "Illegal command #{cmd} (must be a string)"
end
expected_index = Core.write_request(run_loop, cmd)
result = nil
begin
Timeout::timeout(timeout, TimeoutError) do
result = Core.read_response(run_loop, expected_index)
end
rescue TimeoutError => _
raise TimeoutError, "Time out waiting for UIAutomation run-loop for command #{cmd}. Waiting for index:#{expected_index}"
end
result
end
|
.stop(run_loop, out = Dir.pwd) ⇒ Object
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
|
# File 'lib/run_loop/core.rb', line 700
def self.stop(run_loop, out=Dir.pwd)
return if run_loop.nil?
results_dir = run_loop[:results_dir]
dest = out
Core.pids_for_run_loop(run_loop) do |pid|
Process.kill('TERM', pid.to_i)
end
FileUtils.mkdir_p(dest)
if results_dir
pngs = Dir.glob(File.join(results_dir, 'Run 1', '*.png'))
else
pngs = []
end
FileUtils.cp(pngs, dest) if pngs and pngs.length > 0
end
|
.validate_script(script) ⇒ Object
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
|
# File 'lib/run_loop/core.rb', line 723
def self.validate_script(script)
if script.is_a?(String)
unless File.exist?(script)
raise "Unable to find file: #{script}"
end
elsif script.is_a?(Symbol)
script = Core.script_for_key(script)
unless script
raise "Unknown script for symbol: #{script}. Options: #{Core::SCRIPTS.keys.join(', ')}"
end
else
raise "Script must be a symbol or path: #{script}"
end
script
end
|