Module: ScreenObject::Accessors

Defined in:
lib/screen-object/accessors.rb

Overview

include Gem ‘screen-object’ into project Gemfile to add this Gem into project. include require ‘screen-object’ into environment file. doing this , it will load screen object methods for usage..

Instance Method Summary collapse

Instance Method Details

#button(name, locator) ⇒ Object

Button class generates all the methods related to different operations that can be performed on the button.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/screen-object/accessors.rb', line 26

def button(name, locator)

    # generates method for clicking button.
    # this method will not return any value.
    # @example click on 'Submit' button.
    # button(:login_button,"xpath~//UIButtonField")
    # def click_login_button
    #  login_button # This will click on the button.
    # end
    define_method(name) do
      ScreenObject::AppElements::Button.new(locator).tap
    end

    # generates method for checking the existence of the button.
    # this method will return true or false based on object displayed or not.
    # @example check if 'Submit' button exists on the screen.
    # button(:login_button,"xpath~//UIButtonField")
    # DSL to check existence of login button
    # def check_login_button
    #  login_button?  # This will return true or false based on existence of button.
    # end
    define_method("#{name}?") do
      ScreenObject::AppElements::Button.new(locator).exists?
    end

    # generates method for checking if button is enabled.
    # this method will return true if button is enabled otherwise false.
    # @example check if 'Submit' button enabled on the screen.
    # button(:login_button,"xpath~//UIButtonField")
    # DSL to check if button is enabled or not
    # def enable_login_button
    # login_button_enabled? # This will return true or false if button is enabled or disabled.
    # end
    define_method("#{name}_enabled?") do
      ScreenObject::AppElements::Button.new(locator).enabled?
    end

    # generates method for getting text for value attribute.
    # this method will return the text containing into value attribute.
    # @example To retrieve text from value attribute of the defined object i.e. 'Submit' button.
    # button(:login_button,"xpath~//UIButtonField")
    # DSL to retrieve text for value attribute.
    # def value_login_button
    #  login_button_value  # This will return the text of the value attribute of the 'Submit' button object.
    # end
    define_method("#{name}_value") do
      ScreenObject::AppElements::Button.new(locator).value
    end

    # generates method for scrolling on the screen and click on the button.
    # this should be used for iOS platform.
    # scroll to the first element with exact target static text or name.
    # this method will not return any value.
    # button(:login_button,"xpath~//UIButtonField")
    # def scroll_button
    #  login_button_scroll # This will not return any value. It will scroll on the screen until object found and click
    #                        on the object i.e. button. This is iOS specific method and should not be used for android application
    # end
    define_method("#{name}_scroll") do
      # direction = options[:direction] || 'down'
      ScreenObject::AppElements::Button.new(locator).scroll_for_element_click
    end

    # generates method for scrolling on iOS application screen and click on button. This method should be used when button text is dynamic..
    # this should be used for iOS platform.
    # scroll to the first element with exact target dynamic text or name.
    # this method will not return any value.
    # @param [text] is the actual text of the button containing.
    # DSL to scroll on iOS application screen and click on button. This method should be used when button text is dynamic..
    # button(:login_button,"UIButtonField")  # button API should have class name as shown in this example.
    # OR
    # button(:login_button,"UIButtonField/UIButtonFieldtext")  # button API should have class name as shown in this example.
    # def scroll_button
    #   login_button_scroll_dynamic(text)    # This will not return any value. we need to pass button text or name as parameter.
    #                                          It will scroll on the screen until object with same name found and click on
    #                                          the object i.e. button. This is iOS specific method and should not be used
    #                                          for android application.
    # end
    define_method("#{name}_scroll_dynamic") do |text|
      # direction = options[:direction] || 'down'
      ScreenObject::AppElements::Button.new(locator).scroll_for_dynamic_element_click(text)
    end

    # generates method for scrolling on Android application screen and click on button. This method should be used when button text is static...
    # this should be used for Android platform.
    # scroll to the first element containing target static text or name.
    # this method will not return any value.
    # DSL to scroll on Android application screen and click on button. This method should be used when button text is static...
    # @param [text] is the actual text of the button containing.
    # button(:login_button,"xpath~//UIButtonField")
    # def scroll_button
    #   login_button_scroll_(text)  # This will not return any value. we need to pass button text or
    #                                 name[containing targeted text or name] as parameter.It will scroll on the
    #                                 screen until object with same name found and click on the
    #                                 object i.e. button. This is Android specific method and should not be used
    #                                 for iOS application. This method matches with containing text for the
    #                                 button on the screen and click on it.
    # end
    define_method("#{name}_scroll_") do |text|
      ScreenObject::AppElements::Button.new(locator).click_text(text)
    end

    # generates method for scrolling on Android application screen and click on button. This method should be used when button text is dynamic......
    # this should be used for Android platform.
    # scroll to the first element containing target dynamic text or name.
    # this method will not return any value.
    # DSL to scroll on Android application screen and click on button. This method should be used when button text is dynamic......
    # @param [text] is the actual text of the button containing.
    # button(:login_button,"UIButtonField")  # button API should have class name as shown in this example.
    # OR
    # button(:login_button,"UIButtonField/UIButtonFieldtext")  # button API should have class name as shown in this example.
    #
    # def scroll_button
    #   login_button_scroll_dynamic_(text) # This will not return any value. we need to pass button text or name
    #                                        [containing targeted text or name] as parameter.It will scroll on the screen
    #                                        until object with same name found and click on the object i.e. button.
    #                                        This is Android specific method and should not be used for iOS application.
    #                                        This method matches with containing text for the button on the screen and click on it.
    #
    # end
    define_method("#{name}_scroll_dynamic_") do |text|
      ScreenObject::AppElements::Button.new(locator).click_dynamic_text(text)
    end

    # generates method for scrolling on the screen and click on the button.
    # this should be used for Android platform.
    # scroll to the first element with exact target static text or name.
    # this method will not return any value.
    # 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.
    # @param [text] is the actual text of the button containing.
    # button(:login_button,"xpath~//UIButtonField")
    # def scroll_button
    #   login_button_scroll_exact_(text)       # This will not return any value. we need to pass button text or name
    #                                            [EXACT text or name] as parameter. It will scroll on the screen until
    #                                            object with same name found and click on the object i.e. button.
    #                                            This is Android specific method and should not be used for iOS application.
    #                                            This method matches with exact text for the button on the screen and click on it.
    #
    # end
    define_method("#{name}_scroll_exact_") do |text|
      ScreenObject::AppElements::Button.new(locator).click_exact_text(text)
    end

    #generates method for scrolling on the screen and click on the button.
    #This should be used for Android platform.
    # Scroll to the first element with exact target dynamic text or name.
    # this method will not return any value.
    # 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.
    # @param [text] is the actual text of the button containing.
    # button(:login_button,"UIButtonField")  # button API should have class name as shown in this example.
    # OR
    # button(:login_button,"UIButtonField/UIButtonFieldtext")  # button API should have class name as shown in this example.
    # def scroll_button
    #   login_button_scroll_dynamic_exact_(text) # This will not return any value. we need to pass button text or name
    #                                             [EXACT text or name] as parameter. It will scroll on the screen until object
    #                                             with same name found and click on the object i.e. button. This is Android specific
    #                                             method and should not be used for iOS application. This method matches with exact
    #                                             text for the button on the screen and click on it.
    #
    # end
    define_method("#{name}_scroll_dynamic_exact_") do |text|
      ScreenObject::AppElements::Button.new(locator).click_dynamic_exact_text(text)
    end

end

#checkbox(name, locator) ⇒ Object

Checkbox class generates all the methods related to different operations that can be performed on the check box on the screen.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/screen-object/accessors.rb', line 193

def checkbox(name, locator)

  # generates method for checking the checkbox object.
  # this will not return any value
  # @example check if 'remember me' checkbox is not checked.
  # checkbox(:remember_me,"xpath~//UICheckBox")
  # DSL to check the 'remember me' check box.
  # def check_remember_me_checkbox
  #   check_remember_me # This method will check the check box.
  # end
  define_method("check_#{name}") do
    ScreenObject::AppElements::CheckBox.new(locator).check
  end

  # generates method for un-checking the checkbox.
  # this will not return any value
  # @example uncheck if 'remember me' check box is checked.
  # DSL to uncheck remember me check box
  # def uncheck_remember_me_check_box
  #   uncheck_remember_me # This method will uncheck the check box if it's checked.
  # end
  define_method("uncheck_#{name}") do
    ScreenObject::AppElements::CheckBox.new(locator).uncheck
  end

  # generates method for checking the existence of object.
  # this will return true or false based on object is displayed or not.
  # @example check if 'remember me' check box exists on the screen.
  # def exist_remember_me_check_box
  #   remember_me? # This method is used to return true or false based on 'remember me' check box exist.
  # end
  define_method("#{name}?") do
    ScreenObject::AppElements::CheckBox.new(locator).exists?
  end

  # generates method for checking if checkbox is already checked.
  # this will return true if checkbox is checked.
  # @example check if 'remember me' check box is not checked.
  # def exist_remember_me_check_box
  #   remember_me? # This method is used to return true or false based on 'remember me' check box exist.
  # end
  define_method("#{name}_checked?") do
    ScreenObject::AppElements::CheckBox.new(locator).checked?
  end

end

#element(name, locator) ⇒ Object

elements class generates all the methods related to general elements operation



449
450
451
452
453
454
# File 'lib/screen-object/accessors.rb', line 449

def element(name, locator)
  #generates method for elements object
  define_method("#{name}") do
    ScreenObject::AppElements::Element.new(locator)
  end
end

#image(name, locator) ⇒ Object

Image class generates all the methods related to different operations that can be performed on the image object on the screen.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/screen-object/accessors.rb', line 413

def image(name,locator)

  # generates method for checking the existence of the image.
  # this will return true or false based on if image is available or not
  # @example check if 'logo' image is displayed on the page
  # text(:logo,"xpath~//UITextField")
  # DSL for clicking the logo image.
  # def click_logo
  #  logo # This will click on the logo text on the screen.
  # end
  define_method("#{name}?") do
    ScreenObject::AppElements::Image.new(locator).exists?
  end

  #generates method for clicking image
  # this will not return any value.
  # @example clicking on logo image.
  # text(:logo,"xpath~//UITextField")
  # DSL for clicking the logo image.
  # def click_logo
  #  logo # This will click on the logo text on the screen.
  # end
  define_method("#{name}") do
    ScreenObject::AppElements::Image.new(locator).click
  end
end

#table(name, locator) ⇒ Object

table class generates all the methods related to different operations that can be performed on the table object on the screen.



441
442
443
444
445
446
# File 'lib/screen-object/accessors.rb', line 441

def table(name, locator)
  #generates method for counting total no of cells in table
  define_method("#{name}_cell_count") do
    ScreenObject::AppElements::Table.new(locator).cell_count
  end
end

#text(name, locator) ⇒ Object

Text class generates all the methods related to different operations that can be performed on the text object on the screen.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/screen-object/accessors.rb', line 242

def text(name,locator)


  # generates method for clicking button.
  # this method will not return any value.
  # @example click on 'Submit' button.
  # button(:login_button,"xpath~//UIButtonField")
  # def click_login_button
  #  login_button # This will click on the button.
  # end
  define_method(name) do
    ScreenObject::AppElements::Text.new(locator).tap
  end

  # generates method for checking if text exists on the screen.
  # this will return true or false based on if text is available or not
  # @example check if 'Welcome' text is displayed on the page
  # text(:welcome_text,"xpath~//UITextField")
  # # DSL for clicking the Welcome text.
  # def verify_welcome_text
  #   welcome_text? # This will check if object exists and return true..
  # end
  define_method("#{name}?") do
    ScreenObject::AppElements::Text.new(locator).exists?
  end

  # generates method for clicking on text object.
  # this will NOT return any value.
  # @example check if 'Welcome' text is displayed on the page
  # text(:welcome_text,"xpath~//UITextField")
  # DSL for clicking the Welcome text.
  # def click_welcome_text
  #   welcome_text # This will click on the Welcome text on the screen.
  # end
  define_method("#{name}") do
    ScreenObject::AppElements::Text.new(locator).click
  end

  # generates method for retrieving text of the object.
  # this will return value of text attribute of the object.
  # @example retrieve text of 'Welcome' object on the page.
  # text(:welcome_text,"xpath~//UITextField")
  # DSL to retrieve text of the attribute text.
  # def get_welcome_text
  #   welcome_text_text # This will return text of value of attribute 'text'.
  # end
  define_method("#{name}_text") do
    ScreenObject::AppElements::Text.new(locator).text
  end

  # generates method for checking dynamic text object.
  # this will return true or false based on object is displayed or not.
  # @example check if 'Welcome' text is displayed on the page
  # @param [text] is the actual text of the button containing.
  # 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.
  # DSL to check if the text that is sent as argument exists on the screen. Returns true or false
  # text(:welcome_guest,"xpath~//UITextField")
  # def dynamic_welcome_guest(Welcome_<guest_name>)
  # welcome_text_dynamic?(welcome_<guest_name>)  # This will return true or false based welcome text exists on the screen.
  # end
  define_method("#{name}_dynamic?") do |text|
    ScreenObject::AppElements::Text.new(locator).dynamic_text_exists?(text)
  end

  # generates method for retrieving text of the value attribute of the object.
  # this will return text of value attribute of the object.
  # @example retrieve text of the 'Welcome' text.
  # text(:welcome_text,"xpath~//UITextField")
  # DSL to retrieve text of the attribute text.
  # def get_welcome_text
  #   welcome_text_value # This will return text of value of attribute 'text'.
  # end
  define_method("#{name}_value") do
    ScreenObject::AppElements::Text.new(locator).value
  end

  # generates method for checking dynamic text object.
  # this will return actual test for an object.
  # @example check if 'Welcome' text is displayed on the page
  # @param [text] is the actual text of the button containing.
  # 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.
  # DSL to check if the text that is sent as argument exists on the screen. Returns true or false
  # text(:welcome_guest,"xpath~//UITextField")
  # def dynamic_welcome_guest(Welcome_<guest_name>)
  # welcome_text_dynamic?(welcome_<guest_name>)  # This will return true or false based welcome text exists on the screen.
  # end
  define_method("#{name}_dynamic_text") do |text|
    ScreenObject::AppElements::Text.new(locator).dynamic_text(text)
  end

end

#text_field(name, locator) ⇒ Object

text_field class generates all the methods related to different operations that can be performed on the text_field object on the screen.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/screen-object/accessors.rb', line 335

def text_field(name,locator)

  # generates method for setting text into text field.
  # There is no return value for this method.
  # @example setting username field.
  # DSL for entering text in username text field.
  # def set_username_text_field(username)
  #   self.username=username   # This method will enter text into username text field.
  # end
  define_method("#{name}=") do |text|
    ScreenObject::AppElements::TextField.new(locator).text=(text)
  end

  # generates method for comparing expected and actual text.
  # this will return text of text attribute of the object.
  # @example retrieve text of the 'username' text field.
  # text_field(:username,"xpath~//UITextField")
  # DSL to retrieve text of the attribute text.
  # def get_welcome_text
  #   username_text # This will return text containing in text field attribute.
  # end
  define_method("#{name}") do
    ScreenObject::AppElements::TextField.new(locator).text
  end

  # generates method for clear pre populated text from the text field.
  # this will not return any value.
  # @example clear text of the username text field.
  # text_field(:username,"xpath~//UITextField")
  # DSL to clear the text of the text field.
  # def clear_text
  #   clear_username # This will clear the pre populated user name text field.
  # end
  define_method("clear_#{name}") do
    ScreenObject::AppElements::TextField.new(locator).clear
  end

  # generates method for checking if text_field exists on the screen.
  # this will return true or false based on if text field is available or not
  # @example check if 'username' text field is displayed on the page
  # text_field(:username,"xpath~//UITextField")
  # # DSL for clicking the username text.
  # def exists_username
  #   username? # This will return if object exists on the screen.
  # end
  define_method("#{name}?") do
    ScreenObject::AppElements::TextField.new(locator).exists?
  end

  # generates method for retrieving text of the value attribute of the object.
  # this will return text of value attribute of the object.
  # @example retrieve text of the 'username' text_field.
  # text_field(:username,"xpath~//UITextField")
  # DSL to retrieve text of the attribute text.
  # def get_username_text
  #   username_value # This will return text of value of attribute 'text'.
  # end
  define_method("#{name}_value") do
    ScreenObject::AppElements::TextField.new(locator).value
  end


  # generates method for checking if button is enabled.
  # this method will return true if button is enabled otherwise false.
  # @example check if 'Submit' button enabled on the screen.
  # button(:login_button,"xpath~//UIButtonField")
  # DSL to check if button is enabled or not
  # def enable_login_button
  # login_button_enabled? # This will return true or false if button is enabled or disabled.
  # end
  define_method("#{name}_enabled?") do
    ScreenObject::AppElements::TextField.new(locator).enabled?
  end

end