Module: Calabash::Cucumber::RotationHelpers

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

Overview

Provides methods for rotating a device in a direction or to a particular orientation.

Instance Method Summary collapse

Methods included from Logging

#calabash_info, #calabash_warn

Instance Method Details

#recalibrate_after_rotationObject



169
170
171
# File 'lib/calabash-cucumber/rotation_helpers.rb', line 169

def recalibrate_after_rotation
  uia_query :window
end

#rotate(dir) ⇒ Object

Note:

For legacy support the ‘dir` argument can be a String or Symbol. Please update your code to pass a Symbol.

Rotates the device in the direction indicated by ‘dir`.

Examples:

rotate left

rotate :left

rotate right

rotate :right

rotate down

rotate :down

rotate up

rotate :up

Parameters:

  • dir (Symbol)

    The position of the home button after the rotation. Can be one of ‘{:down | :left | :right | :up }`.



131
132
133
134
135
136
137
138
139
140
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
# File 'lib/calabash-cucumber/rotation_helpers.rb', line 131

def rotate(dir)
  dir = dir.to_sym
  current_orientation = status_bar_orientation().to_sym
  rotate_cmd = nil
  case dir
    when :left then
      if current_orientation == :down
        rotate_cmd = 'left_home_down'
      elsif current_orientation == :right
        rotate_cmd = 'left_home_right'
      elsif current_orientation == :left
        rotate_cmd = 'left_home_left'
      elsif current_orientation == :up
        rotate_cmd = 'left_home_up'
      end
    when :right then
      if current_orientation == :down
        rotate_cmd = 'right_home_down'
      elsif current_orientation == :left
        rotate_cmd = 'right_home_left'
      elsif current_orientation == :right
        rotate_cmd = 'right_home_right'
      elsif current_orientation == :up
        rotate_cmd = 'right_home_up'
      end
  end

  if rotate_cmd.nil?
    if full_console_logging?
      puts "Could not rotate device in direction '#{dir}' with orientation '#{current_orientation} - will do nothing"
    end
  else
    result = playback("rotate_#{rotate_cmd}")
    recalibrate_after_rotation
    result
  end
end

#rotate_home_button_to(dir) ⇒ Symbol

Note:

Refer to Apple’s documentation for clarification about left vs. right landscape orientations.

Note:

For legacy support the ‘dir` argument can be a String or Symbol. Please update your code to pass a Symbol.

Note:

For legacy support ‘:top` and `top` are synonyms for `:up`. Please update your code to pass `:up`.

Note:

For legacy support ‘:bottom` and `bottom` are synonyms for `:down`. Please update your code to pass `:down`.

Note:

This method generates verbose messages when full console logging is enabled. See Logging#full_console_logging?.

Note:

A rotation will only occur if your view controller and application support the target orientation.

Rotates the home button to a position relative to the status bar.

Examples:

portrait

rotate_home_button_to :down

upside down

rotate_home_button_to :up

landscape with left home button AKA: right landscape

rotate_home_button_to :left

landscape with right home button AKA: left landscape

rotate_home_button_to :right

Parameters:

  • dir (Symbol)

    The position of the home button after the rotation. Can be one of ‘{:down | :left | :right | :up }`.

Returns:

  • (Symbol)

    The position of the home button relative to the status bar when all rotations have been completed.



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/calabash-cucumber/rotation_helpers.rb', line 55

def rotate_home_button_to(dir)
  dir_sym = dir.to_sym
  if dir_sym.eql?(:top)
    if full_console_logging?
      calabash_warn "converting '#{dir}' to ':up' - please adjust your code"
    end
    dir_sym = :up
  end

  if dir_sym.eql?(:bottom)
    if full_console_logging?
      calabash_warn "converting '#{dir}' to ':down' - please adjust your code"
    end
    dir_sym = :down
  end

  directions = [:down, :up, :left, :right]
  unless directions.include?(dir_sym)
    screenshot_and_raise "expected one of '#{directions}' as an arg to 'rotate_home_button_to but found '#{dir}'"
  end

  res = status_bar_orientation()
  if res.nil?
    screenshot_and_raise "expected 'status_bar_orientation' to return a non-nil value"
  else
    res = res.to_sym
  end

  return res if res.eql? dir_sym

  rotation_candidates.each { |candidate|
    if full_console_logging?
      puts "try to rotate to '#{dir_sym}' using '#{candidate}'"
    end
    playback(candidate)
    # need a longer sleep for cloud testing
    sleep(0.4)
    recalibrate_after_rotation()

    res = status_bar_orientation
    if res.nil?
      screenshot_and_raise "expected 'status_bar_orientation' to return a non-nil value"
    else
      res = res.to_sym
    end

    return if res.eql? dir_sym
  }

  if full_console_logging?
    calabash_warn "Could not rotate home button to '#{dir}'."
    calabash_warn 'Is rotation enabled for this controller?'
    calabash_warn "Will return 'down'"
  end
  :down
end