module ScreenObject::Accessors
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..
Public Instance Methods
Checkbox class generates all the methods related to different operations that can be performed on the check box on the screen.
# 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
elements class generates all the methods related to general elements operation
# 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 class generates all the methods related to different operations that can be performed on the image object on the screen.
# 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 class generates all the methods related to different operations that can be performed on the table object on the screen.
# 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 class generates all the methods related to different operations that can be performed on the text object on the screen.
# 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
class generates all the methods related to different operations that can be performed on the text_field
object on the screen.
# 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