Class: UIAuto::Instruments

Inherits:
Object
  • Object
show all
Defined in:
lib/uiauto/instruments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, reporter, opts = {}) ⇒ Instruments

Returns a new instance of Instruments.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/uiauto/instruments.rb', line 11

def initialize(script, reporter, opts = {})
  @reporter  = reporter
  @script    = script
  @trace     = opts[:trace]
  @results   = opts[:results]
  @device    = opts[:device]
  @simulator = opts[:simulator]
  @app       = opts[:app] || default_application

  FileUtils.mkdir_p(@results) unless File.exists?(@results)
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def app
  @app
end

#deviceObject

Returns the value of attribute device.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def device
  @device
end

#resultsObject

Returns the value of attribute results.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def results
  @results
end

#scriptObject

Returns the value of attribute script.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def script
  @script
end

#simulatorObject

Returns the value of attribute simulator.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def simulator
  @simulator
end

#traceObject

Returns the value of attribute trace.



9
10
11
# File 'lib/uiauto/instruments.rb', line 9

def trace
  @trace
end

Instance Method Details

#commandObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/uiauto/instruments.rb', line 23

def command
  command = ["xcrun instruments"]
  command << "-w #{device_id}" if device_id
  command << "-D #{@trace}"
  command << "-t #{automation_template_location}"
  command << @app
  command << "-e UIASCRIPT #{@script}"
  command << "-e UIARESULTSPATH #{@results}"

  command.join(" ")
end

#executeObject



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
# File 'lib/uiauto/instruments.rb', line 35

def execute
  launch_simulator
  select_device_family

  instruments = ChildProcess.build(*command.split(" "))
  master, slave = if PTY.respond_to?(:open)
                    PTY.open
                  else
                    [File.new("/dev/ptyuf", "w"), File.open("/dev/ttyuf", "r")]
                  end
  instruments.io.stdout = master
  instruments.io.stderr = master
  instruments.duplex = true
  instruments.start
  master.close

  begin
    loop do
      buffer = slave.readpartial(8192)
      @reporter.parse_instruments_output(buffer)
    end
  rescue EOFError
    @reporter.script_finish(@script)
  ensure
    slave.close
  end
end