Module: Calabash::Cucumber::StatusBarHelpers

Includes:
Logging
Included in:
Core
Defined in:
lib/calabash-cucumber/status_bar_helpers.rb

Overview

Contains methods for interacting with the status bar.

Instance Method Summary collapse

Methods included from Logging

#calabash_info, #calabash_warn

Instance Method Details

#device_orientation(force_down = false) ⇒ Symbol

Note:

This method is not used internally by the gem. It is provided as an alternative to ‘status_bar_orientation`. We recommend that you use `status_bar_orientation` whenever possible.

Note:

Devices that are lying on a flat surface will report their orientation as ‘face up’ or ‘face down’. In order to translate gestures based on orientation, Calabash must have left, right, up, or down orientation. To that end, if a device is lying flat, this method will ***force*** a down orientation. This will happen regardless of the value of the ‘force_down` optional argument.

Returns the device orientation as reported by ‘[[UIDevice currentDevice] orientation]`.

Parameters:

  • force_down (Boolean) (defaults to: false)

    if true, do rotations until a down orientation is achieved

Returns:

  • (Symbol)

    Returns the device orientation as one of ‘:up, :left, :right`.

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 31

def device_orientation(force_down=false)
  res = map(nil, :orientation, :device).first

  if ['face up', 'face down'].include?(res)
    if full_console_logging?
      if force_down
        puts "WARN  found orientation '#{res}' - will rotate to force orientation to 'down'"
      end
    end

    return res unless force_down
    return rotate_home_button_to :down
  end

  return res unless res.eql?('unknown')
  return res unless force_down
  rotate_home_button_to(:down)
end

#landscape?Boolean

Is the device in the landscape orientation?

Returns:

  • (Boolean)

    Returns true if the device is in the ‘left’ or ‘right’ orientation.



76
77
78
79
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 76

def landscape?
  o = status_bar_orientation
  o.eql?('right') or o.eql?('left')
end

#portrait?Boolean

Is the device in the portrait orientation?

Returns:

  • (Boolean)

    Returns true if the device is in the ‘up’ or ‘down’ orientation.



67
68
69
70
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 67

def portrait?
  o = status_bar_orientation
  o.eql?('up') or o.eql?('down')
end

#status_bar_orientationString

Note:

You should always prefer to use this method over ‘device_orientation`.

Note:

This method works even if a status bar is not visible.

Returns the home button position relative to the status bar.

Returns:

  • (String)

    Returns the device orientation as one of ‘| ‘up’ | ‘left’ | ‘right’‘.



59
60
61
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 59

def status_bar_orientation
  map(nil, :orientation, :status_bar).first
end