module CUKES::PageUtils

Public Instance Methods

click_on(clickable_element) click to toggle source

Description : clicks on the given web element Author : Chandra sekaran Arguments :

clickable_element: element object

Return argument : a boolean value

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 57
def click_on(clickable_element)
  wait_until(PageObject.default_element_wait) { element.visible? } rescue Exception
  clickable_element.scroll_into_view rescue Exception
  #if clickable_element.enabled?
    clickable_element.focus rescue Exception
    clickable_element.click
    wait_for_page_load
  #end
  return true
rescue Exception => ex
  clickable_element.fire_event("click") rescue Exception
  $log.error("Error in clicking web element : #{ex}")
  return false
end
compare_string(str_actual, str_expected) click to toggle source

Description : compares two strings and throws error if the strings are unequal Author : Chandra sekaran Arguments :

str_actual      : actual string value
str_expected    : expected string value
# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 40
def compare_string(str_actual, str_expected)
  raise "The expected string is '#{str_expected}' but the actual string value is '#{str_actual}'" if str_actual != str_expected
end
get_execution_delay_time() click to toggle source

Description : function for getting the delay (in seconds) between the parallel executions Author : Chandra sekaran Return argument : delay in seconds

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 144
def get_execution_delay_time
  num_seconds = 0
  if DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "second"
    num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i
  elsif DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "minute"
    num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i * 60
  elsif DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "hour"
    num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i * 60 * 60
  end
  [0, 1].include?(NO_OF_PARALLEL_THREADS.to_i) ? 0 : NO_OF_PARALLEL_THREADS.to_i * num_seconds
end
get_steps(feature) click to toggle source

Description : function for getting all steps under the current running scenario Author : Chandra sekaran Argument :

feature       : feature object of current running feature file

Return argument :

arr_steps     : array of steps
# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 132
def get_steps(feature)
  arr_steps = []
  feature.feature_elements[$scenario_count].steps.each do |step|
    arr_steps << step.name
  end
  arr_steps
end
is_text_present(page_object, str_text, num_wait = PageObject.default_element_wait) click to toggle source

Description : checks if the given text is present in the current page or iframe Author : Chandra sekaran Arguments :

page_object      : page object
str_text         : string text
num_wait         : time out value

Return argument : a boolean value

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 80
def is_text_present(page_object, str_text, num_wait = PageObject.default_element_wait)
  wait_for_loading
  page_object.wait_until(num_wait, "Failure in finding text '#{str_text}' in the page #{page_object}") do
    page_object.text.include? str_text
  end
  return true
rescue Exception => ex
  return false
end
refresh_page(page_object) click to toggle source

Description : refresh the current web page Author : Chandra sekaran Arguments :

page_object      : page object
# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 95
def refresh_page(page_object)
  page_object.refresh
  wait_for_page_load
end
switch_to_application_window() click to toggle source

Description : closes other browser windows and switches to application main window Author : Chandra sekaran

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 112
def switch_to_application_window
  if @browser.window_handles.size > 1
    window_to_close = @browser.window_handle
    parent_window = @browser.window_handles.find_all { |window| window != @browser.window_handle }
    @browser.switch_to.window window_to_close
    puts("Closing window " + @browser.title)
    @browser.close
    parent_window.each do |window|
      @browser.switch_to.window window
    end
  end
end
switch_to_next_window() click to toggle source

Description : function for moving to newly opened browser window Author : Chandra sekaran

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 103
def switch_to_next_window
  raise "Number of windows should be two" if @browser.window_handles.size != 2
  window_to_switch = @browser.window_handles.find { |window| window != @browser.window_handle }
  @browser.switch_to.window window_to_switch
end
wait_ajax_for_loading() click to toggle source

Description : waits until the web page is loading and ajax requests are completed Author : Gomathi

# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 47
def wait_ajax_for_loading
  wait_for_ajax(PageObject.default_element_wait)  # waits until ajax request is complete
end
wait_for_object(element, str_error_message = "Failure in finding the element", num_wait_time = PageObject.default_element_wait) click to toggle source

Description : waits until the web element is visible Author : Chandra sekaran Arguments :

element           : page object element
str_error_message : error message to be displayed if web element is not visible within the timeout
num_wait_time     : number of seconds to wait
# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 20
def wait_for_object(element, str_error_message = "Failure in finding the element", num_wait_time = PageObject.default_element_wait)
  wait_until(num_wait_time, str_error_message) { element.visible? }
end
wait_for_page_load(str_error_message = "Failure in page load", num_wait_time = PageObject.default_page_wait) click to toggle source

Description : waits until the web page title is visible Author : Chandra sekaran Arguments :

str_error_message : error message to be displayed if web page title is not within the timeout
num_wait_time     : number of seconds to wait
# File lib/friendly/cukes/framework/library/app_utils/page_utils.rb, line 30
def wait_for_page_load(str_error_message = "Failure in page load", num_wait_time = PageObject.default_page_wait)
  wait_until(num_wait_time, str_error_message) { title != '' }
end