Class: Calabash::Cucumber::Device
- Inherits:
-
Object
- Object
- Calabash::Cucumber::Device
- 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.
Instance Attribute Summary collapse
-
#device_family ⇒ String
readonly
The device family of this device.
-
#device_name ⇒ Object
readonly
Requires calabash server > 0.16.2.
-
#endpoint ⇒ String
readonly
The http address of this device.
-
#form_factor ⇒ Object
readonly
The form factor of this device.
-
#ios_version ⇒ String
readonly
The ‘major.minor.` version of iOS that is running on this device.
-
#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.
-
#model_identifier ⇒ String
readonly
Requires calabash server > 0.16.2.
-
#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.
Instance Method Summary collapse
-
#device? ⇒ Boolean
Is this device a device or simulator?.
-
#initialize(endpoint, version_data) ⇒ Device
constructor
Creates a new instance of Device.
-
#ios10? ⇒ Boolean
Is this device running iOS 10?.
-
#ios11? ⇒ Boolean
Is this device running iOS 11?.
-
#ios5? ⇒ Boolean
Is this device running iOS 5?.
-
#ios6? ⇒ Boolean
Is this device running iOS 6?.
-
#ios7? ⇒ Boolean
Is this device running iOS 7?.
-
#ios8? ⇒ Boolean
Is this device running iOS 8?.
-
#ios9? ⇒ Boolean
Is this device running iOS 9?.
-
#ios_gte_11? ⇒ Boolean
Is this device running iOS 11?.
-
#ios_major_version ⇒ String
The major iOS version of this device.
-
#ipad? ⇒ Boolean
Is this device an iPad?.
-
#ipad_pro? ⇒ Boolean
Is this device an iPad Pro?.
-
#iphone? ⇒ Boolean
Is this device an iPhone?.
-
#iphone_35in? ⇒ Boolean
Is this device an iPhone 3.5in?.
-
#iphone_4in? ⇒ Boolean
Is this device a 4in iPhone?.
-
#iphone_6? ⇒ Boolean
Is this device an iPhone 6?.
-
#iphone_6_plus? ⇒ Boolean
Is this device an iPhone 6+?.
-
#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?.
-
#simulator? ⇒ Boolean
Is this device a simulator or physical device?.
Constructor Details
#initialize(endpoint, version_data) ⇒ Device
Creates a new instance of Device.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/calabash-cucumber/device.rb', line 141 def initialize (endpoint, version_data) @endpoint = endpoint @model_identifier = version_data['model_identifier'] @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'] @form_factor = version_data['form_factor'] @device_name = version_data['device_name'] family = version_data['device_family'] if family @device_family = family.split(' ').first end # Available 0.10.2 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 # 0.16.2 server adds 'ios_version' key unless @ios_version @ios_version = version_data['iOS_version'] end end |
Instance Attribute Details
#device_family ⇒ String (readonly)
Also know as the form factor.
The device family of this device.
43 44 45 |
# File 'lib/calabash-cucumber/device.rb', line 43 def device_family @device_family end |
#device_name ⇒ Object (readonly)
Requires calabash server > 0.16.2
For simulators, this is known to return ‘< form factor > Simulator’
For devices, this will return the name of the device as seen in Xcode.
132 133 134 |
# File 'lib/calabash-cucumber/device.rb', line 132 def device_name @device_name end |
#endpoint ⇒ String (readonly)
The http address of this device.
29 30 31 |
# File 'lib/calabash-cucumber/device.rb', line 29 def endpoint @endpoint end |
#form_factor ⇒ Object (readonly)
The form factor of this device. Will be one of:
* ipad
* iphone 4in
* iphone 3.5in
* iphone 6
* iphone 6+
* ipad pro
* unknown
95 96 97 |
# File 'lib/calabash-cucumber/device.rb', line 95 def form_factor @form_factor end |
#ios_version ⇒ String (readonly)
The ‘major.minor.` version of iOS that is running on this device.
60 61 62 |
# File 'lib/calabash-cucumber/device.rb', line 60 def ios_version @ios_version 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.
82 83 84 |
# File 'lib/calabash-cucumber/device.rb', line 82 def iphone_app_emulated_on_ipad @iphone_app_emulated_on_ipad end |
#model_identifier ⇒ String (readonly)
Requires calabash server > 0.16.2
-
iPhone7,1
-
iPhone5,2
-
iPad6,1
-
iPad6,8
123 124 125 |
# File 'lib/calabash-cucumber/device.rb', line 123 def model_identifier @model_identifier 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,
:native_scale => 2
}
112 113 114 |
# File 'lib/calabash-cucumber/device.rb', line 112 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.
72 73 74 |
# File 'lib/calabash-cucumber/device.rb', line 72 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.
49 50 51 |
# File 'lib/calabash-cucumber/device.rb', line 49 def simulator_details @simulator_details end |
Instance Method Details
#device? ⇒ Boolean
Is this device a device or simulator?
184 185 186 |
# File 'lib/calabash-cucumber/device.rb', line 184 def device? !simulator? end |
#ios10? ⇒ Boolean
Is this device running iOS 10?
256 257 258 |
# File 'lib/calabash-cucumber/device.rb', line 256 def ios10? ios_version_object.major == 10 end |
#ios11? ⇒ Boolean
Is this device running iOS 11?
250 251 252 |
# File 'lib/calabash-cucumber/device.rb', line 250 def ios11? ios_version_object.major == 11 end |
#ios5? ⇒ Boolean
Is this device running iOS 5?
286 287 288 |
# File 'lib/calabash-cucumber/device.rb', line 286 def ios5? ios_version_object.major == 5 end |
#ios6? ⇒ Boolean
Is this device running iOS 6?
280 281 282 |
# File 'lib/calabash-cucumber/device.rb', line 280 def ios6? ios_version_object.major == 6 end |
#ios7? ⇒ Boolean
Is this device running iOS 7?
274 275 276 |
# File 'lib/calabash-cucumber/device.rb', line 274 def ios7? ios_version_object.major == 7 end |
#ios8? ⇒ Boolean
Is this device running iOS 8?
268 269 270 |
# File 'lib/calabash-cucumber/device.rb', line 268 def ios8? ios_version_object.major == 8 end |
#ios9? ⇒ Boolean
Is this device running iOS 9?
262 263 264 |
# File 'lib/calabash-cucumber/device.rb', line 262 def ios9? ios_version_object.major == 9 end |
#ios_gte_11? ⇒ Boolean
Is this device running iOS 11?
244 245 246 |
# File 'lib/calabash-cucumber/device.rb', line 244 def ios_gte_11? ios_version_object.major >= 11 end |
#ios_major_version ⇒ String
The major iOS version of this device.
238 239 240 |
# File 'lib/calabash-cucumber/device.rb', line 238 def ios_major_version ios_version_object.major.to_s end |
#ipad? ⇒ Boolean
Is this device an iPad?
202 203 204 |
# File 'lib/calabash-cucumber/device.rb', line 202 def ipad? device_family.eql? GESTALT_IPAD end |
#ipad_pro? ⇒ Boolean
Is this device an iPad Pro?
232 233 234 |
# File 'lib/calabash-cucumber/device.rb', line 232 def ipad_pro? form_factor == 'ipad pro' end |
#iphone? ⇒ Boolean
Is this device an iPhone?
190 191 192 |
# File 'lib/calabash-cucumber/device.rb', line 190 def iphone? device_family.eql? GESTALT_IPHONE end |
#iphone_35in? ⇒ Boolean
Is this device an iPhone 3.5in?
226 227 228 |
# File 'lib/calabash-cucumber/device.rb', line 226 def iphone_35in? form_factor == 'iphone 3.5in' end |
#iphone_4in? ⇒ Boolean
Is this device a 4in iPhone?
208 209 210 |
# File 'lib/calabash-cucumber/device.rb', line 208 def iphone_4in? form_factor == 'iphone 4in' end |
#iphone_6? ⇒ Boolean
Is this device an iPhone 6?
214 215 216 |
# File 'lib/calabash-cucumber/device.rb', line 214 def iphone_6? form_factor == 'iphone 6' end |
#iphone_6_plus? ⇒ Boolean
Is this device an iPhone 6+?
220 221 222 |
# File 'lib/calabash-cucumber/device.rb', line 220 def iphone_6_plus? form_factor == 'iphone 6+' 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?
297 298 299 |
# File 'lib/calabash-cucumber/device.rb', line 297 def iphone_app_emulated_on_ipad? iphone_app_emulated_on_ipad end |
#ipod? ⇒ Boolean
Is this device an iPod?
196 197 198 |
# File 'lib/calabash-cucumber/device.rb', line 196 def ipod? device_family.eql? GESTALT_IPOD end |
#simulator? ⇒ Boolean
Is this device a simulator or physical device?
173 174 175 176 177 178 179 180 |
# File 'lib/calabash-cucumber/device.rb', line 173 def simulator? details = simulator_details if details details != "" else false end end |