screen-object 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/ChangeLog +7 -0
  4. data/Gemfile +9 -0
  5. data/Rakefile +28 -0
  6. data/cucumber.yml +4 -0
  7. data/features/button.feature +28 -0
  8. data/features/checkbox.feature +11 -0
  9. data/features/navigation.feature +10 -0
  10. data/features/step_definitions/button_step.rb +46 -0
  11. data/features/step_definitions/checkbox_step.rb +12 -0
  12. data/features/step_definitions/navigation_steps.rb +14 -0
  13. data/features/step_definitions/table_step.rb +5 -0
  14. data/features/step_definitions/textfield_step.rb +5 -0
  15. data/features/support/appium.txt +9 -0
  16. data/features/support/appium_ios.txt +11 -0
  17. data/features/support/env.rb +30 -0
  18. data/features/support/screen.rb +79 -0
  19. data/features/support/screens/buttons_screen.rb +8 -0
  20. data/features/support/screens/landing_screen.rb +6 -0
  21. data/features/support/screens/main_screen.rb +6 -0
  22. data/features/table.feature +11 -0
  23. data/features/textfield.feature +10 -0
  24. data/lib/screen-object.rb +161 -0
  25. data/lib/screen-object/.DS_Store +0 -0
  26. data/lib/screen-object/accessors.rb +457 -0
  27. data/lib/screen-object/accessors/button.rb +36 -0
  28. data/lib/screen-object/accessors/checkbox.rb +38 -0
  29. data/lib/screen-object/accessors/element.rb +144 -0
  30. data/lib/screen-object/accessors/image.rb +25 -0
  31. data/lib/screen-object/accessors/table.rb +26 -0
  32. data/lib/screen-object/accessors/text.rb +46 -0
  33. data/lib/screen-object/accessors/textfield.rb +41 -0
  34. data/lib/screen-object/appium_server.rb +58 -0
  35. data/lib/screen-object/elements.rb +21 -0
  36. data/lib/screen-object/load_appium.rb +31 -0
  37. data/lib/screen-object/screen_factory.rb +43 -0
  38. data/lib/screen-object/version.rb +4 -0
  39. data/screen-object.gemspec +28 -0
  40. data/spec/integration/appium_server_spec.rb +24 -0
  41. data/spec/lib/appium_server_spec.rb +59 -0
  42. data/spec/lib/screen_object_spec.rb +37 -0
  43. data/spec/screen-object/button_spec.rb +25 -0
  44. data/spec/screen-object/checkbox_spec.rb +35 -0
  45. data/spec/screen-object/element_spec.rb +205 -0
  46. data/spec/screen-object/image_spec.rb +21 -0
  47. data/spec/screen-object/text_field_spec.rb +37 -0
  48. data/spec/screen-object/text_spec.rb +29 -0
  49. data/spec/spec_helper.rb +29 -0
  50. metadata +201 -0
Binary file
@@ -0,0 +1,457 @@
1
+ =begin
2
+ ***********************************************************************************************************
3
+ Copyright 2016 Capital One Services, LLC
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS,
10
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ See the License for the specific language governing permissions and limitations under the License.
12
+ ***********************************************************************************************************
13
+ =end
14
+
15
+ module ScreenObject
16
+
17
+ # contains module level methods that are added into your screen objects.
18
+ # when you include the ScreenObject module. These methods will be generated as services for screens.
19
+
20
+ # include Gem 'screen-object' into project Gemfile to add this Gem into project.
21
+ # include require 'screen-object' into environment file. doing this , it will load screen object methods for usage..
22
+
23
+ module Accessors
24
+
25
+ # Button class generates all the methods related to different operations that can be performed on the button.
26
+ def button(name, locator)
27
+
28
+ # generates method for clicking button.
29
+ # this method will not return any value.
30
+ # @example click on 'Submit' button.
31
+ # button(:login_button,"xpath~//UIButtonField")
32
+ # def click_login_button
33
+ # login_button # This will click on the button.
34
+ # end
35
+ define_method(name) do
36
+ ScreenObject::AppElements::Button.new(locator).tap
37
+ end
38
+
39
+ # generates method for checking the existence of the button.
40
+ # this method will return true or false based on object displayed or not.
41
+ # @example check if 'Submit' button exists on the screen.
42
+ # button(:login_button,"xpath~//UIButtonField")
43
+ # DSL to check existence of login button
44
+ # def check_login_button
45
+ # login_button? # This will return true or false based on existence of button.
46
+ # end
47
+ define_method("#{name}?") do
48
+ ScreenObject::AppElements::Button.new(locator).exists?
49
+ end
50
+
51
+ # generates method for checking if button is enabled.
52
+ # this method will return true if button is enabled otherwise false.
53
+ # @example check if 'Submit' button enabled on the screen.
54
+ # button(:login_button,"xpath~//UIButtonField")
55
+ # DSL to check if button is enabled or not
56
+ # def enable_login_button
57
+ # login_button_enabled? # This will return true or false if button is enabled or disabled.
58
+ # end
59
+ define_method("#{name}_enabled?") do
60
+ ScreenObject::AppElements::Button.new(locator).enabled?
61
+ end
62
+
63
+ # generates method for getting text for value attribute.
64
+ # this method will return the text containing into value attribute.
65
+ # @example To retrieve text from value attribute of the defined object i.e. 'Submit' button.
66
+ # button(:login_button,"xpath~//UIButtonField")
67
+ # DSL to retrieve text for value attribute.
68
+ # def value_login_button
69
+ # login_button_value # This will return the text of the value attribute of the 'Submit' button object.
70
+ # end
71
+ define_method("#{name}_value") do
72
+ ScreenObject::AppElements::Button.new(locator).value
73
+ end
74
+
75
+ # generates method for scrolling on the screen and click on the button.
76
+ # this should be used for iOS platform.
77
+ # scroll to the first element with exact target static text or name.
78
+ # this method will not return any value.
79
+ # button(:login_button,"xpath~//UIButtonField")
80
+ # def scroll_button
81
+ # login_button_scroll # This will not return any value. It will scroll on the screen until object found and click
82
+ # on the object i.e. button. This is iOS specific method and should not be used for android application
83
+ # end
84
+ define_method("#{name}_scroll") do
85
+ # direction = options[:direction] || 'down'
86
+ ScreenObject::AppElements::Button.new(locator).scroll_for_element_click
87
+ end
88
+
89
+ # generates method for scrolling on iOS application screen and click on button. This method should be used when button text is dynamic..
90
+ # this should be used for iOS platform.
91
+ # scroll to the first element with exact target dynamic text or name.
92
+ # this method will not return any value.
93
+ # @param [text] is the actual text of the button containing.
94
+ # DSL to scroll on iOS application screen and click on button. This method should be used when button text is dynamic..
95
+ # button(:login_button,"UIButtonField") # button API should have class name as shown in this example.
96
+ # OR
97
+ # button(:login_button,"UIButtonField/UIButtonFieldtext") # button API should have class name as shown in this example.
98
+ # def scroll_button
99
+ # login_button_scroll_dynamic(text) # This will not return any value. we need to pass button text or name as parameter.
100
+ # It will scroll on the screen until object with same name found and click on
101
+ # the object i.e. button. This is iOS specific method and should not be used
102
+ # for android application.
103
+ # end
104
+ define_method("#{name}_scroll_dynamic") do |text|
105
+ # direction = options[:direction] || 'down'
106
+ ScreenObject::AppElements::Button.new(locator).scroll_for_dynamic_element_click(text)
107
+ end
108
+
109
+ # generates method for scrolling on Android application screen and click on button. This method should be used when button text is static...
110
+ # this should be used for Android platform.
111
+ # scroll to the first element containing target static text or name.
112
+ # this method will not return any value.
113
+ # DSL to scroll on Android application screen and click on button. This method should be used when button text is static...
114
+ # @param [text] is the actual text of the button containing.
115
+ # button(:login_button,"xpath~//UIButtonField")
116
+ # def scroll_button
117
+ # login_button_scroll_(text) # This will not return any value. we need to pass button text or
118
+ # name[containing targeted text or name] as parameter.It will scroll on the
119
+ # screen until object with same name found and click on the
120
+ # object i.e. button. This is Android specific method and should not be used
121
+ # for iOS application. This method matches with containing text for the
122
+ # button on the screen and click on it.
123
+ # end
124
+ define_method("#{name}_scroll_") do |text|
125
+ ScreenObject::AppElements::Button.new(locator).click_text(text)
126
+ end
127
+
128
+ # generates method for scrolling on Android application screen and click on button. This method should be used when button text is dynamic......
129
+ # this should be used for Android platform.
130
+ # scroll to the first element containing target dynamic text or name.
131
+ # this method will not return any value.
132
+ # DSL to scroll on Android application screen and click on button. This method should be used when button text is dynamic......
133
+ # @param [text] is the actual text of the button containing.
134
+ # button(:login_button,"UIButtonField") # button API should have class name as shown in this example.
135
+ # OR
136
+ # button(:login_button,"UIButtonField/UIButtonFieldtext") # button API should have class name as shown in this example.
137
+ #
138
+ # def scroll_button
139
+ # login_button_scroll_dynamic_(text) # This will not return any value. we need to pass button text or name
140
+ # [containing targeted text or name] as parameter.It will scroll on the screen
141
+ # until object with same name found and click on the object i.e. button.
142
+ # This is Android specific method and should not be used for iOS application.
143
+ # This method matches with containing text for the button on the screen and click on it.
144
+ #
145
+ # end
146
+ define_method("#{name}_scroll_dynamic_") do |text|
147
+ ScreenObject::AppElements::Button.new(locator).click_dynamic_text(text)
148
+ end
149
+
150
+ # generates method for scrolling on the screen and click on the button.
151
+ # this should be used for Android platform.
152
+ # scroll to the first element with exact target static text or name.
153
+ # this method will not return any value.
154
+ # DSL to scroll on Android application screen and click on button. This method should be used when button text is static. it matches with exact text.
155
+ # @param [text] is the actual text of the button containing.
156
+ # button(:login_button,"xpath~//UIButtonField")
157
+ # def scroll_button
158
+ # login_button_scroll_exact_(text) # This will not return any value. we need to pass button text or name
159
+ # [EXACT text or name] as parameter. It will scroll on the screen until
160
+ # object with same name found and click on the object i.e. button.
161
+ # This is Android specific method and should not be used for iOS application.
162
+ # This method matches with exact text for the button on the screen and click on it.
163
+ #
164
+ # end
165
+ define_method("#{name}_scroll_exact_") do |text|
166
+ ScreenObject::AppElements::Button.new(locator).click_exact_text(text)
167
+ end
168
+
169
+ #generates method for scrolling on the screen and click on the button.
170
+ #This should be used for Android platform.
171
+ # Scroll to the first element with exact target dynamic text or name.
172
+ # this method will not return any value.
173
+ # DSL to scroll on Android application screen and click on button. This method should be used when button text is dynamic. it matches with exact text.
174
+ # @param [text] is the actual text of the button containing.
175
+ # button(:login_button,"UIButtonField") # button API should have class name as shown in this example.
176
+ # OR
177
+ # button(:login_button,"UIButtonField/UIButtonFieldtext") # button API should have class name as shown in this example.
178
+ # def scroll_button
179
+ # login_button_scroll_dynamic_exact_(text) # This will not return any value. we need to pass button text or name
180
+ # [EXACT text or name] as parameter. It will scroll on the screen until object
181
+ # with same name found and click on the object i.e. button. This is Android specific
182
+ # method and should not be used for iOS application. This method matches with exact
183
+ # text for the button on the screen and click on it.
184
+ #
185
+ # end
186
+ define_method("#{name}_scroll_dynamic_exact_") do |text|
187
+ ScreenObject::AppElements::Button.new(locator).click_dynamic_exact_text(text)
188
+ end
189
+
190
+ end # end of button class.
191
+
192
+ # Checkbox class generates all the methods related to different operations that can be performed on the check box on the screen.
193
+ def checkbox(name, locator)
194
+
195
+ # generates method for checking the checkbox object.
196
+ # this will not return any value
197
+ # @example check if 'remember me' checkbox is not checked.
198
+ # checkbox(:remember_me,"xpath~//UICheckBox")
199
+ # DSL to check the 'remember me' check box.
200
+ # def check_remember_me_checkbox
201
+ # check_remember_me # This method will check the check box.
202
+ # end
203
+ define_method("check_#{name}") do
204
+ ScreenObject::AppElements::CheckBox.new(locator).check
205
+ end
206
+
207
+ # generates method for un-checking the checkbox.
208
+ # this will not return any value
209
+ # @example uncheck if 'remember me' check box is checked.
210
+ # DSL to uncheck remember me check box
211
+ # def uncheck_remember_me_check_box
212
+ # uncheck_remember_me # This method will uncheck the check box if it's checked.
213
+ # end
214
+ define_method("uncheck_#{name}") do
215
+ ScreenObject::AppElements::CheckBox.new(locator).uncheck
216
+ end
217
+
218
+ # generates method for checking the existence of object.
219
+ # this will return true or false based on object is displayed or not.
220
+ # @example check if 'remember me' check box exists on the screen.
221
+ # def exist_remember_me_check_box
222
+ # remember_me? # This method is used to return true or false based on 'remember me' check box exist.
223
+ # end
224
+ define_method("#{name}?") do
225
+ ScreenObject::AppElements::CheckBox.new(locator).exists?
226
+ end
227
+
228
+ # generates method for checking if checkbox is already checked.
229
+ # this will return true if checkbox is checked.
230
+ # @example check if 'remember me' check box is not checked.
231
+ # def exist_remember_me_check_box
232
+ # remember_me? # This method is used to return true or false based on 'remember me' check box exist.
233
+ # end
234
+ define_method("#{name}_checked?") do
235
+ ScreenObject::AppElements::CheckBox.new(locator).checked?
236
+ end
237
+
238
+ end
239
+
240
+
241
+ # Text class generates all the methods related to different operations that can be performed on the text object on the screen.
242
+ def text(name,locator)
243
+
244
+
245
+ # generates method for clicking button.
246
+ # this method will not return any value.
247
+ # @example click on 'Submit' button.
248
+ # button(:login_button,"xpath~//UIButtonField")
249
+ # def click_login_button
250
+ # login_button # This will click on the button.
251
+ # end
252
+ define_method(name) do
253
+ ScreenObject::AppElements::Text.new(locator).tap
254
+ end
255
+
256
+ # generates method for checking if text exists on the screen.
257
+ # this will return true or false based on if text is available or not
258
+ # @example check if 'Welcome' text is displayed on the page
259
+ # text(:welcome_text,"xpath~//UITextField")
260
+ # # DSL for clicking the Welcome text.
261
+ # def verify_welcome_text
262
+ # welcome_text? # This will check if object exists and return true..
263
+ # end
264
+ define_method("#{name}?") do
265
+ ScreenObject::AppElements::Text.new(locator).exists?
266
+ end
267
+
268
+ # generates method for clicking on text object.
269
+ # this will NOT return any value.
270
+ # @example check if 'Welcome' text is displayed on the page
271
+ # text(:welcome_text,"xpath~//UITextField")
272
+ # DSL for clicking the Welcome text.
273
+ # def click_welcome_text
274
+ # welcome_text # This will click on the Welcome text on the screen.
275
+ # end
276
+ define_method("#{name}") do
277
+ ScreenObject::AppElements::Text.new(locator).click
278
+ end
279
+
280
+ # generates method for retrieving text of the object.
281
+ # this will return value of text attribute of the object.
282
+ # @example retrieve text of 'Welcome' object on the page.
283
+ # text(:welcome_text,"xpath~//UITextField")
284
+ # DSL to retrieve text of the attribute text.
285
+ # def get_welcome_text
286
+ # welcome_text_text # This will return text of value of attribute 'text'.
287
+ # end
288
+ define_method("#{name}_text") do
289
+ ScreenObject::AppElements::Text.new(locator).text
290
+ end
291
+
292
+ # generates method for checking dynamic text object.
293
+ # this will return true or false based on object is displayed or not.
294
+ # @example check if 'Welcome' text is displayed on the page
295
+ # @param [text] is the actual text of the button containing.
296
+ # suppose 'Welcome guest' text appears on the screen for non logged in user and it changes when user logged in on the screen and appears as 'Welcome <guest_name>'. this would be treated as dynamic text since it would be changing based on guest name.
297
+ # DSL to check if the text that is sent as argument exists on the screen. Returns true or false
298
+ # text(:welcome_guest,"xpath~//UITextField")
299
+ # def dynamic_welcome_guest(Welcome_<guest_name>)
300
+ # welcome_text_dynamic?(welcome_<guest_name>) # This will return true or false based welcome text exists on the screen.
301
+ # end
302
+ define_method("#{name}_dynamic?") do |text|
303
+ ScreenObject::AppElements::Text.new(locator).dynamic_text_exists?(text)
304
+ end
305
+
306
+ # generates method for retrieving text of the value attribute of the object.
307
+ # this will return text of value attribute of the object.
308
+ # @example retrieve text of the 'Welcome' text.
309
+ # text(:welcome_text,"xpath~//UITextField")
310
+ # DSL to retrieve text of the attribute text.
311
+ # def get_welcome_text
312
+ # welcome_text_value # This will return text of value of attribute 'text'.
313
+ # end
314
+ define_method("#{name}_value") do
315
+ ScreenObject::AppElements::Text.new(locator).value
316
+ end
317
+
318
+ # generates method for checking dynamic text object.
319
+ # this will return actual test for an object.
320
+ # @example check if 'Welcome' text is displayed on the page
321
+ # @param [text] is the actual text of the button containing.
322
+ # suppose 'Welcome guest' text appears on the screen for non logged in user and it changes when user logged in on the screen and appears as 'Welcome <guest_name>'. this would be treated as dynamic text since it would be changing based on guest name.
323
+ # DSL to check if the text that is sent as argument exists on the screen. Returns true or false
324
+ # text(:welcome_guest,"xpath~//UITextField")
325
+ # def dynamic_welcome_guest(Welcome_<guest_name>)
326
+ # welcome_text_dynamic?(welcome_<guest_name>) # This will return true or false based welcome text exists on the screen.
327
+ # end
328
+ define_method("#{name}_dynamic_text") do |text|
329
+ ScreenObject::AppElements::Text.new(locator).dynamic_text(text)
330
+ end
331
+
332
+ end
333
+
334
+ # text_field class generates all the methods related to different operations that can be performed on the text_field object on the screen.
335
+ def text_field(name,locator)
336
+
337
+ # generates method for setting text into text field.
338
+ # There is no return value for this method.
339
+ # @example setting username field.
340
+ # DSL for entering text in username text field.
341
+ # def set_username_text_field(username)
342
+ # self.username=username # This method will enter text into username text field.
343
+ # end
344
+ define_method("#{name}=") do |text|
345
+ ScreenObject::AppElements::TextField.new(locator).text=(text)
346
+ end
347
+
348
+ # generates method for comparing expected and actual text.
349
+ # this will return text of text attribute of the object.
350
+ # @example retrieve text of the 'username' text field.
351
+ # text_field(:username,"xpath~//UITextField")
352
+ # DSL to retrieve text of the attribute text.
353
+ # def get_welcome_text
354
+ # username_text # This will return text containing in text field attribute.
355
+ # end
356
+ define_method("#{name}") do
357
+ ScreenObject::AppElements::TextField.new(locator).text
358
+ end
359
+
360
+ # generates method for clear pre populated text from the text field.
361
+ # this will not return any value.
362
+ # @example clear text of the username text field.
363
+ # text_field(:username,"xpath~//UITextField")
364
+ # DSL to clear the text of the text field.
365
+ # def clear_text
366
+ # clear_username # This will clear the pre populated user name text field.
367
+ # end
368
+ define_method("clear_#{name}") do
369
+ ScreenObject::AppElements::TextField.new(locator).clear
370
+ end
371
+
372
+ # generates method for checking if text_field exists on the screen.
373
+ # this will return true or false based on if text field is available or not
374
+ # @example check if 'username' text field is displayed on the page
375
+ # text_field(:username,"xpath~//UITextField")
376
+ # # DSL for clicking the username text.
377
+ # def exists_username
378
+ # username? # This will return if object exists on the screen.
379
+ # end
380
+ define_method("#{name}?") do
381
+ ScreenObject::AppElements::TextField.new(locator).exists?
382
+ end
383
+
384
+ # generates method for retrieving text of the value attribute of the object.
385
+ # this will return text of value attribute of the object.
386
+ # @example retrieve text of the 'username' text_field.
387
+ # text_field(:username,"xpath~//UITextField")
388
+ # DSL to retrieve text of the attribute text.
389
+ # def get_username_text
390
+ # username_value # This will return text of value of attribute 'text'.
391
+ # end
392
+ define_method("#{name}_value") do
393
+ ScreenObject::AppElements::TextField.new(locator).value
394
+ end
395
+
396
+
397
+ # generates method for checking if button is enabled.
398
+ # this method will return true if button is enabled otherwise false.
399
+ # @example check if 'Submit' button enabled on the screen.
400
+ # button(:login_button,"xpath~//UIButtonField")
401
+ # DSL to check if button is enabled or not
402
+ # def enable_login_button
403
+ # login_button_enabled? # This will return true or false if button is enabled or disabled.
404
+ # end
405
+ define_method("#{name}_enabled?") do
406
+ ScreenObject::AppElements::TextField.new(locator).enabled?
407
+ end
408
+
409
+ end
410
+
411
+
412
+ # Image class generates all the methods related to different operations that can be performed on the image object on the screen.
413
+ def image(name,locator)
414
+
415
+ # generates method for checking the existence of the image.
416
+ # this will return true or false based on if image is available or not
417
+ # @example check if 'logo' image is displayed on the page
418
+ # text(:logo,"xpath~//UITextField")
419
+ # DSL for clicking the logo image.
420
+ # def click_logo
421
+ # logo # This will click on the logo text on the screen.
422
+ # end
423
+ define_method("#{name}?") do
424
+ ScreenObject::AppElements::Image.new(locator).exists?
425
+ end
426
+
427
+ #generates method for clicking image
428
+ # this will not return any value.
429
+ # @example clicking on logo image.
430
+ # text(:logo,"xpath~//UITextField")
431
+ # DSL for clicking the logo image.
432
+ # def click_logo
433
+ # logo # This will click on the logo text on the screen.
434
+ # end
435
+ define_method("#{name}") do
436
+ ScreenObject::AppElements::Image.new(locator).click
437
+ end
438
+ end
439
+
440
+ # table class generates all the methods related to different operations that can be performed on the table object on the screen.
441
+ def table(name, locator)
442
+ #generates method for counting total no of cells in table
443
+ define_method("#{name}_cell_count") do
444
+ ScreenObject::AppElements::Table.new(locator).cell_count
445
+ end
446
+ end
447
+
448
+ # elements class generates all the methods related to general elements operation
449
+ def element(name, locator)
450
+ #generates method for elements object
451
+ define_method("#{name}") do
452
+ ScreenObject::AppElements::Element.new(locator)
453
+ end
454
+ end
455
+
456
+ end # end of Accessors module
457
+ end # end of screen object module