Module: Calabash::Cucumber::StatusBarHelpers

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

Instance Method Details

#device_orientationSymbol

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'.

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

Returns:

  • (Symbol)

    Returns the device orientation as one of {'down', 'up', 'left', 'right', 'face up', 'face down', 'unknown'}.

See Also:



27
28
29
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 27

def device_orientation
  Map.map(nil, :orientation, :device).first
end

#landscape?Boolean

Is the device in the landscape orientation?

Returns:

  • (Boolean)

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



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

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.



89
90
91
92
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 89

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

#status_bar_detailsObject

Returns details about the status bar like the frame, its visibility, and orientation.

Requires calabash server 0.20.0.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 48

def status_bar_details
  result = http({:method => :get, :raw => true, :path => "statusBar"})
  if result == ""
    RunLoop::log_debug("status_bar_details is only available in Calabash iOS >= 0.20.0")
    RunLoop::log_debug("Using default status bar details based on orientation.")

    if portrait?
      {
        "frame" => {
          "y" => 0,
          "height" => 20,
          "width" => 375,
          "x" => 0
        },
        "hidden" => false,
        "orientation" => status_bar_orientation,
        "warning" => "These are default values.  Update the server to 0.20.0"
      }
    else
      {
        "frame" => {
          "y" => 0,
          "height" => 10,
          "width" => 375,
          "x" => 0
        },
        "hidden" => false,
        "orientation" => status_bar_orientation,
        "warning" => "These are default values.  Update the server to 0.20.0"
      }
    end
  else
    hash = JSON.parse(result)
    hash["results"]
  end
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 {'down' | 'up' | 'left' | 'right'}.



40
41
42
# File 'lib/calabash-cucumber/status_bar_helpers.rb', line 40

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