Class: Calabash::Cucumber::Device
- Inherits:
-
Object
- Object
- Calabash::Cucumber::Device
- 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
-
#device_family ⇒ String
readonly
The device family of this device.
-
#endpoint ⇒ String
readonly
The http address of this device.
-
#ios_version ⇒ String
readonly
The ‘major.minor.` version of iOS that is running on this device.
-
#iphone_4in ⇒ Boolean
readonly
Indicates whether or not this device has a 4in screen.
-
#iphone_app_emulated_on_ipad ⇒ Boolean
readonly
Indicates whether or not the app under test on this device is an iPhone-only app that is being emulated on an iPad.
-
#screen_dimensions ⇒ Hash
readonly
For Calabash server version > 0.10.2 provides device specific screen information.
-
#server_version ⇒ String
readonly
The version of the embedded Calabash server that is running in the app under test on this device.
-
#simulator_details ⇒ String
readonly
Additional details about the simulator.
-
#system ⇒ String
readonly
The hardware architecture of this device.
-
#udid ⇒ Object
deprecated
Deprecated.
0.10.0 no replacement
Instance Method Summary collapse
-
#device? ⇒ Boolean
Is this device a device or simulator?.
-
#framework_version ⇒ String
deprecated
Deprecated.
0.9.169 replaced with ‘server_version`
-
#initialize(endpoint, version_data) ⇒ Device
constructor
Creates a new instance of Device.
-
#ios5? ⇒ Boolean
Is this device running iOS 5?.
-
#ios6? ⇒ Boolean
Is this device running iOS 6?.
-
#ios7? ⇒ Boolean
Is this device running iOS 7?.
-
#ios_major_version ⇒ String
The major iOS version of this device.
-
#ipad? ⇒ Boolean
Is this device an iPad?.
-
#iphone? ⇒ Boolean
Is this device an iPhone?.
-
#iphone_4in? ⇒ Boolean
Is this device a 4in iPhone?.
-
#iphone_5? ⇒ Boolean
deprecated
Deprecated.
0.9.168 replaced with iphone_4in?
-
#iphone_app_emulated_on_ipad? ⇒ Boolean
Is the app that is running an iPhone-only app emulated on an iPad?.
-
#ipod? ⇒ Boolean
Is this device an iPod?.
-
#screen_size ⇒ Hash
The screen size of the device.
-
#simulator? ⇒ Boolean
Is this device a simulator or physical device?.
Methods included from Logging
#calabash_info, #calabash_warn
Constructor Details
#initialize(endpoint, version_data) ⇒ Device
Creates a new instance of Device.
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_family ⇒ String (readonly)
Also know as the form factor.
The device family of this device.
52 53 54 |
# File 'lib/calabash-cucumber/device.rb', line 52 def device_family @device_family end |
#endpoint ⇒ String (readonly)
The http address of this device.
38 39 40 |
# File 'lib/calabash-cucumber/device.rb', line 38 def endpoint @endpoint end |
#ios_version ⇒ String (readonly)
The ‘major.minor.` version of 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_4in ⇒ Boolean (readonly)
Indicates whether or not 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_ipad ⇒ Boolean (readonly)
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.
109 110 111 |
# File 'lib/calabash-cucumber/device.rb', line 109 def iphone_app_emulated_on_ipad @iphone_app_emulated_on_ipad end |
#screen_dimensions ⇒ Hash (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
}
135 136 137 |
# File 'lib/calabash-cucumber/device.rb', line 135 def screen_dimensions @screen_dimensions end |
#server_version ⇒ String (readonly)
The version of the embedded Calabash server that is running in the app under test on this device.
99 100 101 |
# File 'lib/calabash-cucumber/device.rb', line 99 def server_version @server_version end |
#simulator_details ⇒ String (readonly)
Returns 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 |
#system ⇒ String (readonly)
The hardware architecture of this device. Also known as the chip set.
87 88 89 |
# File 'lib/calabash-cucumber/device.rb', line 87 def system @system end |
#udid ⇒ Object
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?
171 172 173 |
# File 'lib/calabash-cucumber/device.rb', line 171 def device? not simulator? end |
#framework_version ⇒ String
0.9.169 replaced with ‘server_version`
The version of the embedded Calabash server running in the app under test on this device.
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?
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?
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?
225 226 227 |
# File 'lib/calabash-cucumber/device.rb', line 225 def ios7? ios_major_version.eql?('7') end |
#ios_major_version ⇒ String
The major iOS version of this device.
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?
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?
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?
195 196 197 |
# File 'lib/calabash-cucumber/device.rb', line 195 def iphone_4in? @iphone_4in end |
#iphone_5? ⇒ Boolean
0.9.168 replaced with iphone_4in?
Deprecated because the iPhone 5S reports as an iPhone6,*.
Is this device an iPhone 5?
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
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?
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?
183 184 185 |
# File 'lib/calabash-cucumber/device.rb', line 183 def ipod? device_family.eql? GESTALT_IPOD end |
#screen_size ⇒ Hash
These values are not dynamically computed; they are constants.
These values are for portrait or upside orientations
The screen size of the device.
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?
165 166 167 |
# File 'lib/calabash-cucumber/device.rb', line 165 def simulator? system.eql?(GESTALT_SIM_SYS) end |