Module: ScreenObject

Defined in:
lib/screen-object.rb,
lib/screen-object/version.rb,
lib/screen-object/accessors.rb,
lib/screen-object/load_appium.rb,
lib/screen-object/appium_server.rb,
lib/screen-object/accessors/text.rb,
lib/screen-object/screen_factory.rb,
lib/screen-object/accessors/image.rb,
lib/screen-object/accessors/table.rb,
lib/screen-object/accessors/button.rb,
lib/screen-object/accessors/element.rb,
lib/screen-object/accessors/checkbox.rb,
lib/screen-object/accessors/textfield.rb

Overview

*********************************************************************************************************** Copyright 2016 Capital One Services, LLC Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ***********************************************************************************************************

Defined Under Namespace

Modules: Accessors, AppElements, Load_App, ScreenFactory Classes: AppiumServer

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(cls) ⇒ Object



30
31
32
# File 'lib/screen-object.rb', line 30

def self.included(cls)
  cls.extend ScreenObject::Accessors
end

Instance Method Details

#backObject



50
51
52
# File 'lib/screen-object.rb', line 50

def back
  driver.back
end

#drag_and_drop_element(source_locator, source_locator_value, target_locator, target_locator_value) ⇒ Object



146
147
148
149
150
151
# File 'lib/screen-object.rb', line 146

def drag_and_drop_element(source_locator,source_locator_value,target_locator,target_locator_value)
  l_draggable = driver.find_element(source_locator,source_locator_value)
  l_droppable = driver.find_element(target_locator,target_locator_value)
  obj1= Appium::TouchAction.new
  obj1.long_press(:x => l_draggable.location.x,:y => l_draggable.location.y).move_to(:x => l_droppable.location.x,:y => l_droppable.location.y).release.perform
end

#driverObject



34
35
36
# File 'lib/screen-object.rb', line 34

def driver
  ScreenObject::AppElements::Element.new('').driver
end

#enterObject



66
67
68
# File 'lib/screen-object.rb', line 66

def enter
  #pending implementation
end

#keyboard_hideObject



153
154
155
156
157
158
159
# File 'lib/screen-object.rb', line 153

def keyboard_hide
  begin
  driver.hide_keyboard
  rescue
    false
  end
end

#landscapeObject



42
43
44
# File 'lib/screen-object.rb', line 42

def landscape
  driver.driver.rotate :landscape
end

#portraitObject



46
47
48
# File 'lib/screen-object.rb', line 46

def portrait
  driver.driver.rotate :portrait
end

#scroll_down_click(locator, locator_value, num_loop = 15) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/screen-object.rb', line 88

def scroll_down_click(locator,locator_value,num_loop = 15)
  scr = driver.window_size
  screenHeightStart = (scr.height) * 0.5
  scrollStart = screenHeightStart.to_i
  screenHeightEnd = (scr.height) * 0.2
  scrollEnd = screenHeightEnd.to_i
  for i in 0..num_loop
    begin
      if (driver.find_element(locator,locator_value).displayed?)
        driver.find_element(locator,locator_value).click
        break
      end
    rescue
      driver.swipe(:start_x => 0,:start_y => scrollStart,:end_x =>0,:end_y =>scrollEnd,:touchCount => 2,:duration => 0)
      false
    end
  end
end

#scroll_down_find(locator, locator_value, num_loop = 15) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/screen-object.rb', line 70

def scroll_down_find(locator,locator_value,num_loop = 15)
  scr = driver.window_size
  screenHeightStart = (scr.height) * 0.5
  scrollStart = screenHeightStart.to_i
  screenHeightEnd = (scr.height) * 0.2
  scrollEnd = screenHeightEnd.to_i
  for i in 0..num_loop
    begin
      if (driver.find_element(locator,locator_value).displayed?)
        break
      end
    rescue
      driver.swipe(:start_x => 0,:start_y => scrollStart,:end_x =>0,:end_y =>scrollEnd,:touchCount => 2,:duration => 0)
      false
    end
  end
end

#scroll_up_click(locator, locator_value, num_loop = 15) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/screen-object.rb', line 126

def scroll_up_click(locator,locator_value,num_loop = 15)
  scr = driver.window_size
  screenHeightStart = (scr.height) * 0.5
  scrollStart = screenHeightStart.to_i
  screenHeightEnd = (scr.height) * 0.2
  scrollEnd = screenHeightEnd.to_i
  for i in 0..num_loop
    begin
      if (driver.find_element(locator,locator_value).displayed?)
        driver.find_element(locator,locator_value).click
        break
      end
    rescue
      driver.swipe(:start_x => 0,:start_y => scrollEnd,:end_x =>0,:end_y =>scrollStart,:touchCount => 2,:duration => 0)
      false
    end
  end
end

#scroll_up_find(locator, locator_value, num_loop = 15) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/screen-object.rb', line 107

def scroll_up_find(locator,locator_value,num_loop = 15)
  scr = driver.window_size
  screenHeightStart = (scr.height) * 0.5
  scrollStart = screenHeightStart.to_i
  screenHeightEnd = (scr.height) * 0.2
  scrollEnd = screenHeightEnd.to_i
  for i in 0..num_loop
    begin
      if (driver.find_element(locator,locator_value).displayed?)
        break
      end
    rescue
      driver.swipe(:start_x => 0,:start_y => scrollEnd,:end_x =>0,:end_y =>scrollStart,:touchCount => 2,:duration => 0)
      false
    end
  end
end

#swipe(start_x, start_y, end_x, end_y, touch_count, duration) ⇒ Object



38
39
40
# File 'lib/screen-object.rb', line 38

def swipe(start_x,start_y,end_x,end_y,touch_count,duration)
  driver.swipe(:start_x => start_x, :start_y => start_y, :end_x => end_x, :end_y => end_y,:touchCount => touch_count,:duration => duration)
end

#wait_step(timeout = 5, message = nil, &block) ⇒ Object



59
60
61
62
63
64
# File 'lib/screen-object.rb', line 59

def wait_step(timeout = 5, message = nil, &block)
  default_wait = driver.default_wait
  wait = Selenium::WebDriver::Wait.new(:timeout => driver.set_wait(timeout), :message => message)
  wait.until &block
  driver.set_wait(default_wait)
end

#wait_until(timeout = 5, message = nil, &block) ⇒ Object



54
55
56
57
# File 'lib/screen-object.rb', line 54

def wait_until(timeout = 5, message = nil, &block)
  wait = Selenium::WebDriver::Wait.new(timeout: timeout, message: message)
  wait.until &block
end