Class: Platform

Inherits:
Object show all
Defined in:
lib/platform/platform.rb

Overview

The Platform class contains DUT behaviors. It should define all cross-platform methods as stubs which call ‘raise_not_implemented’.

Direct Known Subclasses

AppleTv, Dta, Mdn, Mobile, Passport, Roku, RokuTv, SamsungTv, Sara, Stb, Tivo, Web

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_case, id: nil, config: nil) ⇒ Platform

Public: Initializes a new Platform. NOT FOR USE IN TESTS.

Returns nothing.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/platform/platform.rb', line 18

def initialize(test_case, id: nil, config: nil)
  # Default the test case attribute to a new Object. The screens initialized for syntax eval delegate to this

  # attribute, so if it is nil, then they will have no methods; if it is a TestCase, then they will have all the

  # test case methods in addition to their own. A blank Object is best as it will have only the screen methods.

  @test_case = test_case || Object.new
  @platform = nil
  @model = nil
  @ip_address = nil
  @mac_address = nil
  @id = id
  @remotes = Remotes.new
  @remote_type = nil
  @screens = Screens.new(self)
  @roi = Rois.new(self)
  @key_presser = nil
  @keys = nil
  set_keys(BaseKeys.new)
  @resolution = nil
  @config = config
  @initted = false
  @name = nil
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/platform/platform.rb', line 13

def id
  @id
end

#keysObject (readonly)

Returns the value of attribute keys.



13
14
15
# File 'lib/platform/platform.rb', line 13

def keys
  @keys
end

#remotesObject (readonly)

Returns the value of attribute remotes.



13
14
15
# File 'lib/platform/platform.rb', line 13

def remotes
  @remotes
end

#roiObject (readonly)

Returns the value of attribute roi.



13
14
15
# File 'lib/platform/platform.rb', line 13

def roi
  @roi
end

#screensObject (readonly)

Returns the value of attribute screens.



13
14
15
# File 'lib/platform/platform.rb', line 13

def screens
  @screens
end

Instance Method Details

#alt_parental_controls_pinObject

Public: Gets the alternate parental controls PIN. Must be implemented by each Platform subclass.

Returns the String alternate parental controls PIN.



449
450
451
# File 'lib/platform/platform.rb', line 449

def alt_parental_controls_pin
  $alt_parental_controls_pin || '1111'
end

#app_versionObject

Deprecated: Use software_version instead.



419
420
421
# File 'lib/platform/platform.rb', line 419

def app_version
  software_version
end

#audio_level(args = {}) ⇒ Object

Public: Gets audio level from the device.

sample_length - Integer milliseconds to sample audio (default: 5000). threshold - Integer unit of PCM to return no audio. Humans can’t hear under 1000 (default: 100)

Returns the Integer peak audio level 0 - 32k, where 0 indicates no audio,

or nil if the level could not be determined.


486
487
488
489
490
# File 'lib/platform/platform.rb', line 486

def audio_level(args={})
  lvls = audio_levels(args)
  lev = [lvls[:left], lvls[:right]].max
  (lev > args.fetch(:threshold, 100)) ? lev : 0
end

#audio_level_left(args = {}) ⇒ Object

Public: Gets left channel audio level from the device.

sample_length - Integer milliseconds to sample audio (default: 5000).

Returns the Integer peak audio level of the left channel 0 - 32k, where 0 indicates no audio,

or nil if the level could not be determined.


498
499
500
# File 'lib/platform/platform.rb', line 498

def audio_level_left(args={})
  audio_levels(args)[:left]
end

#audio_level_right(args = {}) ⇒ Object

Public: Gets right channel audio level from the device.

sample_length - Integer milliseconds to sample audio (default: 5000).

Returns the Integer peak audio level of the right channel 0 - 32k, where 0 indicates no audio,

or nil if the level could not be determined.


508
509
510
# File 'lib/platform/platform.rb', line 508

def audio_level_right(args={})
  audio_levels(args)[:right]
end

#audio_present?(args = {}) ⇒ Boolean

Public: Checks if audio is present on the device.

threshold - Integer threshold 0 - 32k audio level must exceed to be considered present (default: 0). sample_length - Integer milliseconds to sample audio (default: 5000).

Returns a Boolean true if audio is present, otherwise false.

Returns:

  • (Boolean)


473
474
475
476
477
# File 'lib/platform/platform.rb', line 473

def audio_present?(args={})
  threshold = args.fetch(:threshold, 0)
  lvl = audio_level(args)
  lvl > threshold
end

#capture_audio(duration, args = {}) ⇒ Object

Public: Captures audio on the device.

duration - Integer total milliseconds to capture audio. key - String name or Array of keys to press to trigger audio capture (default: nil).

If default, no keys will be pressed.

delay - Integer milliseconds to delay after pressing key and before starting frame capture (default: 0). cleanup - Boolean indicating whether to automatically clean up audio during teardown (default: true).

Returns a Hash with the following keys: :audio - String path to audio file. :start_time - Time at which audio capture began.



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/platform/platform.rb', line 523

def capture_audio(duration, args={})
  key = args[:key]
  delay = args.fetch(:delay, 0)
  cleanup = args.fetch(:cleanup, true)
  press_key(key) unless key.nil?
  ret = {audio: nil, start_time: Time.now}
  sleep(delay) if delay > 0
  json = get_json_for_iter.merge(block: true, durationMs: duration)
  resp = @test_case.send(:tmc_post, "/api/audio/record/#{id}", json: json)
  ret[:audio] = resp['filename']
  if cleanup && !ret[:audio].nil?
    @test_case.add_teardown('Cleaning up captured audio') do
      delete_files = [ ret[:audio] ]
      @test_case.send(:tmc_delete, '/api/audio', json: get_json_for_test.merge(files: delete_files))
    end
  end
  ret
end

#capture_frames(duration, args = {}) ⇒ Object

Public: Captures frames on the device.

duration - Integer total milliseconds to capture frames. key - String name or Array of keys to press to trigger audio capture (default: nil).

If default, no keys will be pressed.

delay - Integer milliseconds to delay after pressing key and before starting frame capture (default: 0). cleanup - Boolean indicating whether to automatically clean up frames during teardown (default: true).

If true, all frames in the output which have :keep => false will be deleted at the end of the test.

Returns a Hash with the following keys: :frames - Array of captured frames, each being a Hash with the following keys:

:filename   - String full path to the frame on the server.
:capturedAt - Time at which the frame was captured.
:keep       - Boolean indicating whether to keep the frame if cleanup is true. Initializes false.

:start_time - Time at which frame capture began.



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
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
# File 'lib/platform/platform.rb', line 615

def capture_frames(duration, args={})
  key = args[:key]
  cleanup = args.fetch(:cleanup, true)
  frames = []
  if cleanup
    @test_case.add_teardown('Cleaning up captured frames', frames) do |frame_arr|
      delete_files = frame_arr.reject { |frm| frm[:keep] }.map { |frm| frm[:filename] }
      json = get_json_for_test.merge(files: delete_files)
      @test_case.send(:tmc_delete, '/api/images', json: json)
    end
  end
  # Capture frames

  delay = args.fetch(:delay, 0)
  ret = {}
  if key.nil?
    # this is the best we can do since there is no key. as long as the script runs locally on the TMC,

    # we do not need to worry about clock drift issues

    ret[:start_time] = Time.now
  else
    # use the key press time

    ret[:start_time] = press_key(key, sleep_time: 0) unless key.nil?
  end
  if delay > 0
    sleep(delay)
  end
  json = get_json_for_iter.merge(durationMs: duration)
  result = @test_case.send(:tmc_post, "/api/images/record/#{@id}", json: json)
  raise 'Failed to capture frames!' if result.nil?
  #ret[:start_time] ||= @test_case.to_time(result['startTime'])  # use this start time ONLY if no key and no delay

  result.fetch('images').each do |frm|
    capture_time = frm.fetch('captureTime')
    capture_time = capture_time / 1000.0 unless capture_time.is_a?(String)
    frames << {filename: frm.fetch('path'), capturedAt: @test_case.to_time(capture_time), keep: false}
  end
  ret[:frames] = frames
  # Calculate average FPS and maximum/average margin of error

  max_i, max = [0, 0]
  frame_deltas = frames.each_with_index.map do |f, i|
    if i == 0
      delta = @test_case.get_time_delta(ret[:start_time], f[:capturedAt])
    else
      delta = @test_case.get_time_delta(frames[i - 1][:capturedAt], f[:capturedAt])
    end
    if delta > max
      max_i, max = [i, delta]
    end
    delta
  end
  deltas_sum = frame_deltas.inject(0) {|sum, x| sum + x}
  sec = deltas_sum / 1000.0
  avg_fps = frames.count / sec
  avg_delta = deltas_sum / frame_deltas.count
  logger.debug("Captured #{frames.count} frames in #{sec} s [avg frames/s: #{avg_fps}, " +
                   "max error: #{max} ms (frame #{max_i}), avg error: #{avg_delta} ms]")
  ret
end

#capture_screen(args = {}) ⇒ Object

Public: Captures the dut screen to disk.

filename - String desired path to the file, relative to the test image folder (default: nil).

If default, generates a filename like 'device_<id>_<timestamp>.jpg'.

format - Symbol desired format, can be :raw, :base64 (default: nil). size - Integer desired image size as a percent of original dimensions from 0 - 100 (default: nil). quality - Integer desired quality as a percent 0 - 100 (default: nil).

Returns the String path to the file relative to the test image folder, or image data in the desired format.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/platform/platform.rb', line 159

def capture_screen(args={})
  if self.class <= Web
    # special case for web platform

    meth = :selenium
  else
    # other platforms

    meth = nil
  end
  format = args[:format]
  filename = args[:filename]
  last_captured = args.fetch(:_last_captured, false)
  unless filename.nil?
    logger.warn('`filename\' parameter deprecated and will be removed in future release.', tag: :DEPRECATED)
    raise 'Filename must end in .jpg!' unless filename.end_with?('.jpg')
  end
  case meth
    when :selenium
      # take screenshot via selenium

      resp = self.send(:selenium_request, :post, 'screenshot', {})
    else
      # platform default

      json = get_json_for_iter.merge(path: filename, fromStash: last_captured)
      json[:percentSize] = args[:size] if args.key?(:size)
      json[:quality] = args[:quality] if args.key?(:quality)
      resp = @test_case.send(:tmc_post, "/api/images/#{@id}", json: json)
  end
  if resp.nil?
    if last_captured
      logger.warn('No last screen capture to save', screenshot: false)
      return nil
    else
      raise 'Failed to capture screen!'
    end
  end
  path = resp['path'].gsub('\\', '/')  # just in case

  if format.nil?
    path
  else
    resp = @test_case.send(:tmc_get, "/api/images/#{path}?job=#{@test_case.job}&test=#{@test_case.id}", attr: :body)
    if format == :base64
      Base64.encode64(resp)
    elsif format == :raw
      resp
    end
  end
end

#device_type_is?(*device_types) ⇒ Boolean

Public: Checks if the device type is one of those given.

device_types - Splat Array of String or Symbol device types to check.

Returns a Boolean true if the device type is in the provided list, otherwise false.

Returns:

  • (Boolean)


376
377
378
# File 'lib/platform/platform.rb', line 376

def device_type_is?(*device_types)
  device_types.include?(model.to_sym)
end

#device_type_not?(*device_types) ⇒ Boolean

Public: Checks if the device type is NOT one of those given.

device_types - Splat Array of String or Symbol device types to check.

Returns a Boolean true if the device type is NOT in the provided list, otherwise false.

Returns:

  • (Boolean)


385
386
387
# File 'lib/platform/platform.rb', line 385

def device_type_not?(*device_types)
  !device_type_is?(*device_types)
end

#entitlementsObject

Public: Gets the current device entitlements.

Returns an Array of String entitlement package names.



354
355
356
357
358
359
# File 'lib/platform/platform.rb', line 354

def entitlements
  if @entitlements.nil?
    @entitlements = config['entitlements']
  end
  @entitlements
end

#has_power?Boolean

Public: Checks if the device has physical power.

Returns Boolean true if device has physical power, otherwise false.

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/platform/platform.rb', line 93

def has_power?
  resp = @test_case.send(:tmc_get, "/api/power/#{@id}")
  resp['state']
end

#heightObject

Public: Gets the current device resolution height.

Returns the Integer height in pixels.



327
328
329
# File 'lib/platform/platform.rb', line 327

def height
  resolution[:height]
end

#high_def?Boolean

Public: Checks if the device is HD.

Returns a Boolean true if the device is HD, otherwise false.

Returns:

  • (Boolean)


134
135
136
137
# File 'lib/platform/platform.rb', line 134

def high_def?
  h = resolution[:height]
  [720, 1080].include?(h)
end

#init?(&block) ⇒ Boolean

Public: Initializes the device. Must be implemented by each Platform subclass.

block – Block that performs initialization.

Returns a Boolean true if the device was initialized, otherwise false.

Returns:

  • (Boolean)


459
460
461
462
463
464
465
# File 'lib/platform/platform.rb', line 459

def init?(&block)
  return true if @initted  # no-op if already initted

  unless has_power?
    power_on  # platforms should override this, call super, and add whatever wait/verification is needed

  end
  @initted = block.call
end

#ip_addressObject

Public: Gets the IP address for the dut.

Format is xxx.xxx.xxx.xxx

Returns String IP address.



310
311
312
313
314
315
# File 'lib/platform/platform.rb', line 310

def ip_address
  if @ip_address.nil?
    @ip_address = config['ipAddress']
  end
  @ip_address
end

#is_generic?Boolean

Public: Checks if the device is generic.

Returns a Boolean true if the device is generic, otherwise false.

Returns:

  • (Boolean)


224
225
226
# File 'lib/platform/platform.rb', line 224

def is_generic?
  @platform.nil?
end

#lock(resource, timeout, &block) ⇒ Object

Public: Locks the specified resource to perform an action.

resource - String resource to lock. timeout - Integer lock timeout in milliseconds. block - Block to perform..

Returns the result of the specified block.



679
680
681
# File 'lib/platform/platform.rb', line 679

def lock(resource, timeout, &block)
  @test_case.lock(resource, timeout, device: @id, &block)
end

#mac_addressObject

Public: Gets the MAC address for the dut.

Format is xx:xx:xx:xx:xx:xx

Returns String MAC address.



295
296
297
298
299
300
301
302
303
304
# File 'lib/platform/platform.rb', line 295

def mac_address
  if @mac_address.nil? && !config['macAddress'].nil?
    @mac_address = config['macAddress']
    if @mac_address.length.eql?(12)
      # add separator

      @mac_address = @mac_address.split(/(\w{2})/).select{|x| !x.empty?}.join(':')
    end
  end
  @mac_address
end

#modelObject

Public: Gets the current device model.

Returns the String model name.



344
345
346
347
348
349
# File 'lib/platform/platform.rb', line 344

def model
  if @model.nil?
    @model = config['model']
  end
  @model
end

#nameObject

Public : Gets the name for the dut.

Returns the String device name.



364
365
366
367
368
369
# File 'lib/platform/platform.rb', line 364

def name
  if @name.nil?
    @name = config['name']
  end
  @name
end

#parental_controls_pinObject

Public: Gets the parental controls PIN. Must be implemented by each Platform subclass.

Returns the String parental controls PIN.



442
443
444
# File 'lib/platform/platform.rb', line 442

def parental_controls_pin
  $parental_controls_pin || '0000'
end

#passwordObject

Public: Gets the DUT password from test data.

Expected format: "dut_credentials": {1: {..., password: 'baz'}}

Returns the String password.



435
436
437
# File 'lib/platform/platform.rb', line 435

def password
  creds[:password]
end

#platformObject

Public: Gets the platform name for the dut.

Returns String platform.



334
335
336
337
338
339
# File 'lib/platform/platform.rb', line 334

def platform
  if @platform.nil?
    @platform = config['platform']
  end
  @platform
end

#power_cycle(args = {}) ⇒ Object

Public: Power cycles the device.

delay - Integer milliseconds to wait before powering the device on again (default: 3.sec).

Returns nothing.



117
118
119
120
121
# File 'lib/platform/platform.rb', line 117

def power_cycle(args={})
  power_off
  sleep(args.fetch(:delay, 3.sec))
  power_on
end

#power_offObject

Public: Powers off the device.

Returns nothing.



108
109
110
# File 'lib/platform/platform.rb', line 108

def power_off
  @test_case.send(:tmc_put, "/api/power/#{@id}", :json => {:state => false})
end

#power_onObject

Public: Powers on the device.

Returns nothing.



101
102
103
# File 'lib/platform/platform.rb', line 101

def power_on
  @test_case.send(:tmc_put, "/api/power/#{@id}", :json => {:state => true})
end

#power_on?Boolean

Public: Powers on the device via remote control.

Returns a Boolean true if the device powered on successfully, otherwise false. Raises an Exception with a “Not implemented!” message if it is not implemented by this platform.

Returns:

  • (Boolean)


127
128
129
# File 'lib/platform/platform.rb', line 127

def power_on?
  raise_not_implemented(__method__)
end

#press_key(*args) ⇒ Object

Public: Presses keys. When no arguments are given, this returns the key presser, which defines methods for all of

the valid keys for this platform. See examples.

Examples

press_key.ARROW_DOWN
# => nil

press_key.NUM_3(:sleep_time => 1.sec)
# => nil

press_key('0123', :delay_between_keys => 250.ms, :sleep_time => 5.sec)
# => nil

Returns the key presser or the Time at which the key(s) were pressed.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/platform/platform.rb', line 63

def press_key(*args)
  if args.empty?
    @key_presser
  else
    keys = args[0]
    raise 'Key cannot be nil.' if keys.empty? || keys.nil?
    args = args.fetch(1, {})
    delay_between_keys = args.fetch(:delay_between_keys, 500.ms)
    sleep_time = args.fetch(:sleep_time, 3.sec)
    if keys.is_a?(Integer) || keys =~ /\A\d+\z/
      keys = keys.to_s.chars.to_a
      keys << 'select' if keys.length > 1 && keys.length < 4 && self.class <= Stb
    end
    unless keys.is_a?(Array)
      keys = [keys]
    end
    logger.keypress(keys, message: %Q(Pressing keys: #{keys.join(', ')}))
    json_keys = keys.each_with_index.map do |k, i|
      {key: "KEY_#{k}".upcase, delayMs: (i + 1) == keys.count ? 0.ms : delay_between_keys}
    end
    resp = @test_case.send(:tmc_put, '/api/ir/send', json: 
      {devices: [@id], remote: @remote_type, irData: json_keys, script: @test_case.send(:path)})
    sleep(sleep_time)
    resp['stop'].to_time
  end
end

#record_audio(duration: nil, block: true, window: true, format: 'mp3') ⇒ Object

Public: Records audio on the device.

duration - Integer total milliseconds to record audio. Required if block or window is true (default: nil). block - Boolean block until the recording is finished (default: true). window - Boolean limit recording length to the specified duration (default: true). format - String desired audio format, can be ‘mp3’, ‘wav’, ‘wma’ (default: ‘mp3’).

Returns a Hash with the following keys: :id - String unique identifier for the recording. :path - String path to the recording on the server. :start_time - Time at which recording began. :end_time - Time at which recording stopped.



554
555
556
# File 'lib/platform/platform.rb', line 554

def record_audio(duration: nil, block: true, window: true, format: 'mp3')
  record_media(:audio, duration, block, window, format)
end

#record_video(duration: nil, block: true, window: true, format: 'mp4') ⇒ Object

Public: Records video on the device.

duration - Integer total milliseconds to record video. Required if block or window is true (default: nil). block - Boolean block until the recording is finished (default: true). window - Boolean limit recording length to the specified duration (default: true). format - String desired video format, can be ‘mp4’, ‘avi’, ‘wmv’ (default: ‘mp4’).

Returns a Hash with the following keys: :id - String unique identifier for the recording. :path - String path to the recording on the server. :start_time - Time at which recording began. :end_time - Time at which recording stopped.



583
584
585
# File 'lib/platform/platform.rb', line 583

def record_video(duration: nil, block: true, window: true, format: 'mp4')
  record_media(:video, duration, block, window, format)
end

#remote_type=(type) ⇒ Object

Public: Sets the remote type for the dut. This persists only for the current script. To configure the remote type

permanently, the device configuration must be updated.

type - String remote type to set. Available remotes can be retrieved from ‘dut.remotes’.

Returns nothing.



701
702
703
704
705
# File 'lib/platform/platform.rb', line 701

def remote_type=(type)
  unless remote_type_is?(type)
    @remote_type = type
  end
end

#remote_type_is?(type) ⇒ Boolean

Public: Checks if the current remote type matches the given type.

type - String remote type to check. Available remotes can be retrieved from ‘dut.remotes’.

Returns a Boolean true if the remote type matches, otherwise false.

Returns:

  • (Boolean)


688
689
690
691
692
693
# File 'lib/platform/platform.rb', line 688

def remote_type_is?(type)
  if @remote_type.nil?
    @remote_type = config['remoteType']
  end
  @remote_type == type
end

#reset_videoObject

Public: Resets video on the dut. This should be called after changing resolution on a device.

Returns nothing.



245
246
247
248
# File 'lib/platform/platform.rb', line 245

def reset_video
  logger.info("Resetting video on slot #{@id}")   
  @test_case.send(:tmc_put, "/api/video/reset/#{@id}", :json => {})
end

#resolution(update: false) ⇒ Object

Public: Gets the current device resolution, retrieving it first if necessary.

update - Boolean indicating whether to force update of resolution (default: false).

Returns the resolution as a Hash of :width, :height.



233
234
235
236
237
238
239
240
# File 'lib/platform/platform.rb', line 233

def resolution(update: false)
  if @resolution.nil? || update
    resp = @test_case.send(:tmc_get, "/api/video/info?devices=#{@id}")
    video_inf = resp['videoInfo'][0]
    @resolution = {width: video_inf['width'], height: video_inf['height']}
  end
  @resolution
end

#save_last_screen_captured(args = {}) ⇒ Object

Public: Saves the last captured dut screen to disk.

filename - String desired path to the file, relative to the test image folder (default: nil).

If default, generates a filename like 'device_<id>_<timestamp>.jpg'.

format - Symbol desired format, can be :raw, :base64 (default: nil).

Returns the String path to the file relative to the test image folder, or image data in the desired format.



146
147
148
# File 'lib/platform/platform.rb', line 146

def save_last_screen_captured(args={})
  capture_screen(args.merge(_last_captured: true))
end

#slotObject

Public: Gets the device slot.

Returns the Integer device slot or nil.



44
45
46
# File 'lib/platform/platform.rb', line 44

def slot
  @id
end

#snmp_get(object, args = {}) ⇒ Object

Public: Gets the specified SNMP object from the dut.

object - String object OID to retrieve. port - Integer SNMP port (default: 161). trap_port - Integer SNMP trap port (default: 162). community - String SNMP community string (default: ‘public’). write_community - String SNMP community string (default: ‘public’). version - Symbol SNMP version (default: :SNMPv2c). timeout - Integer timeout in seconds (default: 1). retries - Integer retries (default: 5). transport - Class SNMP transport (default: UDPTransport). max_recv_bytes - Integer maximum receive bytes (default: 8000). use_IPv6 - Boolean indicating whether to use IPv6 (default: false).

True if :host is formatted like an IPv6 address.

Returns a String of value retrieved.



266
267
268
# File 'lib/platform/platform.rb', line 266

def snmp_get(object, args={})
  @test_case.snmp_get(ip_address, object, args)
end

#snmp_set(object, value, args = {}) ⇒ Object

Public: Sets the specified SNMP object on the dut.

object - String object OID to set. value - String value to set. port - Integer SNMP port (default: 161). trap_port - Integer SNMP trap port (default: 162). community - String SNMP community string (default: ‘public’). write_community - String SNMP community string (default: ‘public’). version - Symbol SNMP version (default: :SNMPv2c). timeout - Integer timeout in seconds (default: 1). retries - Integer retries (default: 5). transport - Class SNMP transport (default: UDPTransport). max_recv_bytes - Integer maximum receive bytes (default: 8000). use_IPv6 - Boolean indicating whether to use IPv6 (default: false).

True if :host is formatted like an IPv6 address.

Returns the result.



287
288
289
# File 'lib/platform/platform.rb', line 287

def snmp_set(object, value, args={})
  @test_case.snmp_set(ip_address, object, value, args)
end

#software_versionObject

Public: Gets the device software version.

Returns the String software version.



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/platform/platform.rb', line 392

def software_version
  # Search for a software version defined in script options, in order of specificity.

  # Try the device type first.

  device_type_key = "#{platform}_software_version".downcase.to_sym
  if @test_case.options.include?(device_type_key)
    @test_case.options[:build_code] = @test_case.options[device_type_key]
  end
  # Next, try the platform hierarchy.

  cls = self.class
  loop do
    platform_key = "#{cls.name}_software_version".downcase.to_sym
    if @test_case.options.include?(platform_key)
      @test_case.options[:build_code] = @test_case.options[platform_key]
      break
    end
    break if cls == Platform || cls == cls.superclass
    cls = cls.superclass
  end
  # Next, try the base app_version.

  if @test_case.options.include?(:software_version)
    @test_case.options[:build_code] = @test_case.options[:software_version]
  end
  # Finally, default to build_code.

  @test_case.options[:build_code]
end

#stop_audio(id) ⇒ Object

Public: Stops audio recording on the device.

id - String unique identifier for the recording to stop.

Returns a Hash with the following keys: :id - String unique identifier for the recording. :path - String path to the recording on the server. :start_time - Time at which recording began. :end_time - Time at which recording stopped.



567
568
569
# File 'lib/platform/platform.rb', line 567

def stop_audio(id)
  stop_media(:audio, id)
end

#stop_video(id) ⇒ Object

Public: Stops video recording on the device.

id - String unique identifier for the recording to stop.

Returns a Hash with the following keys: :id - String unique identifier for the recording. :path - String path to the recording on the server. :start_time - Time at which recording began. :end_time - Time at which recording stopped.



596
597
598
# File 'lib/platform/platform.rb', line 596

def stop_video(id)
  stop_media(:video, id)
end

#upload_screenshot(args = {}) ⇒ Object

Public: Uploads a screenshot to the reporting system.

filename - String path to an existing screenshot (default: nil).

If default, a new screenshot will be captured.

Returns nothing.



212
213
214
215
216
217
218
219
# File 'lib/platform/platform.rb', line 212

def upload_screenshot(args={})
  case test_case.options[:reporting_mode]
    when 'twb' # send it to twb

      twb_post_screenshot(:ss_filename => args[:filename])
    else # send it to SWORD

      sword_attach_screenshot("Screenshot from TMC slot #{@id}", nil, args[:filename])
  end
end

#usernameObject

Public: Gets the DUT username from test data.

Expected format: "dut_credentials": {1: {username: 'foo', ...}}

Returns the String username.



427
428
429
# File 'lib/platform/platform.rb', line 427

def username
  creds[:username]
end

#widthObject

Public: Gets the current device resolution width.

Returns the Integer width in pixels.



320
321
322
# File 'lib/platform/platform.rb', line 320

def width
  resolution[:width]
end