Class: Calabash::Cucumber::Device

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/calabash-cucumber/device.rb

Overview

Device encapsulates information about the device or simulator that the app is running on. It also includes the following information about the app that is running on the current device.

  • The version of the embedded Calabash server.

  • Whether or not the app is an iPhone-only app that is being emulated on an iPad.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#calabash_info, #calabash_warn

Constructor Details

#initialize(endpoint, version_data) ⇒ Device

Creates a new instance of Device.

Parameters:

  • endpoint (String)

    the http address of this device

  • version_data (Hash)

    the output of the ‘server_version` function

See Also:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/calabash-cucumber/device.rb', line 144

def initialize (endpoint, version_data)
  simulator_device = version_data['simulator_device']
  @endpoint = endpoint
  @system = version_data['system']
  @device_family = @system.eql?(GESTALT_SIM_SYS) ? simulator_device : @system.split(/[\d,.]/).first
  @simulator_details = version_data['simulator']
  @ios_version = version_data['iOS_version']
  @server_version = version_data['version']
  @iphone_app_emulated_on_ipad = version_data['iphone_app_emulated_on_ipad']
  @iphone_4in = version_data['4inch']
  screen_dimensions = version_data['screen_dimensions']
  if screen_dimensions
    @screen_dimensions = {}
    screen_dimensions.each_pair do |key,val|
      @screen_dimensions[key.to_sym] = val
    end
  end
end

Instance Attribute Details

#device_familyString (readonly)

Note:

Also know as the form factor.

The device family of this device.

Examples:

# will be one of
iPhone
iPod
iPad

Returns:

  • (String)

    the device family



52
53
54
# File 'lib/calabash-cucumber/device.rb', line 52

def device_family
  @device_family
end

#endpointString (readonly)

The http address of this device.

Examples:

http://192.168.0.2:37265

Returns:

  • (String)

    an ip address with port number.



38
39
40
# File 'lib/calabash-cucumber/device.rb', line 38

def endpoint
  @endpoint
end

#ios_versionString (readonly)

The ‘major.minor.` version of iOS that is running on this device.

Examples:

7.1
6.1.2
5.1.1

Returns:

  • (String)

    the version of the iOS that is running on this device



69
70
71
# File 'lib/calabash-cucumber/device.rb', line 69

def ios_version
  @ios_version
end

#iphone_4inBoolean (readonly)

Indicates whether or not this device has a 4in screen.

Returns:

  • (Boolean)

    ‘true` if this device has a 4in screen.



114
115
116
# File 'lib/calabash-cucumber/device.rb', line 114

def iphone_4in
  @iphone_4in
end

#iphone_app_emulated_on_ipadBoolean (readonly)

Note:

If the ‘1x` or `2x` button is visible, then the app is being emulated.

Indicates whether or not the app under test on this device is an

iPhone-only app that is being emulated on an iPad.

Returns:

  • (Boolean)

    ‘true` if the app under test is emulated



109
110
111
# File 'lib/calabash-cucumber/device.rb', line 109

def iphone_app_emulated_on_ipad
  @iphone_app_emulated_on_ipad
end

#screen_dimensionsHash (readonly)

For Calabash server version > 0.10.2 provides device specific screen information.

This is a hash of form:

{
  :sample => 1,
  :height => 1334,
  :width => 750,
  :scale" => 2
}

Returns:

  • (Hash)

    screen dimensions, scale and down/up sampling fraction.



135
136
137
# File 'lib/calabash-cucumber/device.rb', line 135

def screen_dimensions
  @screen_dimensions
end

#server_versionString (readonly)

The version of the embedded Calabash server that is running in the app under test on this device.

Examples:

0.9.168
0.10.0.pre1

Returns:



99
100
101
# File 'lib/calabash-cucumber/device.rb', line 99

def server_version
  @server_version
end

#simulator_detailsString (readonly)

Returns Additional details about the simulator. If this device is a physical device, returns nil.

Returns:

  • (String)

    Additional details about the simulator. If this device is a physical device, returns nil.



58
59
60
# File 'lib/calabash-cucumber/device.rb', line 58

def simulator_details
  @simulator_details
end

#systemString (readonly)

The hardware architecture of this device. Also known as the chip set.

Examples:

# simulator
i386
x86_64
# examples from physical devices
armv6
armv7s
arm64

Returns:

  • (String)

    the hardware architecture of this device. this device.



87
88
89
# File 'lib/calabash-cucumber/device.rb', line 87

def system
  @system
end

#udidObject

Deprecated.

0.10.0 no replacement



119
120
121
# File 'lib/calabash-cucumber/device.rb', line 119

def udid
  @udid
end

Instance Method Details

#device?Boolean

Is this device a device or simulator?

Returns:

  • (Boolean)

    true if this device is a physical device



171
172
173
# File 'lib/calabash-cucumber/device.rb', line 171

def device?
  not simulator?
end

#framework_versionString

Deprecated.

0.9.169 replaced with ‘server_version`

The version of the embedded Calabash server running in the app under test on this device.

Returns:

  • (String)

    the version of the embedded Calabash server

See Also:



272
273
274
275
# File 'lib/calabash-cucumber/device.rb', line 272

def framework_version
  _deprecated('0.9.169', "use 'server_version', instead", :warn)
  @server_version
end

#ios5?Boolean

Is this device running iOS 5?

Returns:

  • (Boolean)

    true if the major version of the OS is 5



237
238
239
# File 'lib/calabash-cucumber/device.rb', line 237

def ios5?
  ios_major_version.eql?('5')
end

#ios6?Boolean

Is this device running iOS 6?

Returns:

  • (Boolean)

    true if the major version of the OS is 6



231
232
233
# File 'lib/calabash-cucumber/device.rb', line 231

def ios6?
  ios_major_version.eql?('6')
end

#ios7?Boolean

Is this device running iOS 7?

Returns:

  • (Boolean)

    true if the major version of the OS is 7



225
226
227
# File 'lib/calabash-cucumber/device.rb', line 225

def ios7?
  ios_major_version.eql?('7')
end

#ios_major_versionString

The major iOS version of this device.

Returns:

  • (String)

    the major version of the OS



219
220
221
# File 'lib/calabash-cucumber/device.rb', line 219

def ios_major_version
  version_hash(ios_version)[:major_version]
end

#ipad?Boolean

Is this device an iPad?

Returns:

  • (Boolean)

    true if this device is an ipad



189
190
191
# File 'lib/calabash-cucumber/device.rb', line 189

def ipad?
  device_family.eql? GESTALT_IPAD
end

#iphone?Boolean

Is this device an iPhone?

Returns:

  • (Boolean)

    true if this device is an iphone



177
178
179
# File 'lib/calabash-cucumber/device.rb', line 177

def iphone?
  device_family.eql? GESTALT_IPHONE
end

#iphone_4in?Boolean

Is this device a 4in iPhone?

Returns:

  • (Boolean)

    true if this device is a 4in iphone



195
196
197
# File 'lib/calabash-cucumber/device.rb', line 195

def iphone_4in?
  @iphone_4in
end

#iphone_5?Boolean

Deprecated.

0.9.168 replaced with iphone_4in?

Note:

Deprecated because the iPhone 5S reports as an iPhone6,*.

Is this device an iPhone 5?

Returns:

  • (Boolean)

    true if this device is an iPhone 5

See Also:



204
205
206
207
# File 'lib/calabash-cucumber/device.rb', line 204

def iphone_5?
  _deprecated('0.9.168', "use 'iphone_4in?' instead", :warn)
  iphone_4in?
end

#iphone_app_emulated_on_ipad?Boolean

Note:

If the app is running in emulation mode, there will be a 1x or 2x scale button visible on the iPad.

Is the app that is running an iPhone-only app emulated on an iPad?

Returns:

  • (Boolean)

    true if the app running on this devices is an iPhone-only app emulated on an iPad



263
264
265
# File 'lib/calabash-cucumber/device.rb', line 263

def iphone_app_emulated_on_ipad?
  iphone_app_emulated_on_ipad
end

#ipod?Boolean

Is this device an iPod?

Returns:

  • (Boolean)

    true if this device is an ipod



183
184
185
# File 'lib/calabash-cucumber/device.rb', line 183

def ipod?
  device_family.eql? GESTALT_IPOD
end

#screen_sizeHash

Note:

These values are not dynamically computed; they are constants.

Note:

These values are for portrait or upside orientations

The screen size of the device.

Returns:

  • (Hash)

    representation of the screen size as a hash with keys ‘:width` and `:height`



249
250
251
252
253
254
# File 'lib/calabash-cucumber/device.rb', line 249

def screen_size
  return screen_dimensions if screen_dimensions
  return { :width => 768, :height => 1024 } if ipad?
  return { :width => 320, :height => 568 } if iphone_4in?
  { :width => 320, :height => 480 }
end

#simulator?Boolean

Is this device a simulator or physical device?

Returns:

  • (Boolean)

    true if this device is a simulator



165
166
167
# File 'lib/calabash-cucumber/device.rb', line 165

def simulator?
  system.eql?(GESTALT_SIM_SYS)
end