Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
library/app_utils/page_utils.rb | 158 | 56 | 84.18%
|
55.36%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
2 =begin |
3 *Name : PageUtils |
4 *Description : module that define methods for commonly used page-object related manipulations |
5 *Author : Chandra sekaran |
6 *Creation Date : 24/04/2015 |
7 *Updation Date : |
8 =end |
9 |
10 module CUKES |
11 module PageUtils |
12 include PageObject |
13 |
14 # Description : waits until the web element is visible |
15 # Author : Chandra sekaran |
16 # Arguments : |
17 # element : page object element |
18 # str_error_message : error message to be displayed if web element is not visible within the timeout |
19 # num_wait_time : number of seconds to wait |
20 # |
21 def wait_for_object(element, str_error_message = "Failure in finding the element", num_wait_time = PageObject.default_element_wait) |
22 wait_until(num_wait_time, str_error_message) { element.visible? } |
23 end |
24 |
25 # Description : waits until the web page title is visible |
26 # Author : Chandra sekaran |
27 # Arguments : |
28 # str_error_message : error message to be displayed if web page title is not within the timeout |
29 # num_wait_time : number of seconds to wait |
30 # |
31 def wait_for_page_load(str_error_message = "Failure in page load", num_wait_time = PageObject.default_page_wait) |
32 wait_until(num_wait_time, str_error_message) { title != '' } |
33 end |
34 |
35 # Description : compares two strings and throws error if the strings are unequal |
36 # Author : Chandra sekaran |
37 # Arguments : |
38 # str_actual : actual string value |
39 # str_expected : expected string value |
40 # |
41 def compare_string(str_actual, str_expected) |
42 raise "The expected string is '#{str_expected}' but the actual string value is '#{str_actual}'" if str_actual != str_expected |
43 end |
44 |
45 # Description : waits until the web page is loading and ajax requests are completed |
46 # Author : Gomathi |
47 # |
48 def wait_ajax_for_loading |
49 wait_for_ajax(PageObject.default_element_wait) # waits until ajax request is complete |
50 end |
51 |
52 # Description : clicks on the given web element |
53 # Author : Chandra sekaran |
54 # Arguments : |
55 # clickable_element: element object |
56 # Return argument : a boolean value |
57 # |
58 def click_on(clickable_element) |
59 wait_until(PageObject.default_element_wait) { element.visible? } rescue Exception |
60 clickable_element.scroll_into_view rescue Exception |
61 #if clickable_element.enabled? |
62 clickable_element.focus rescue Exception |
63 clickable_element.click |
64 wait_for_page_load |
65 #end |
66 return true |
67 rescue Exception => ex |
68 clickable_element.fire_event("click") rescue Exception |
69 $log.error("Error in clicking web element : #{ex}") |
70 return false |
71 end |
72 |
73 # Description : checks if the given text is present in the current page or iframe |
74 # Author : Chandra sekaran |
75 # Arguments : |
76 # page_object : page object |
77 # str_text : string text |
78 # num_wait : time out value |
79 # Return argument : a boolean value |
80 # |
81 def is_text_present(page_object, str_text, num_wait = PageObject.default_element_wait) |
82 wait_for_loading |
83 page_object.wait_until(num_wait, "Failure in finding text '#{str_text}' in the page #{page_object}") do |
84 page_object.text.include? str_text |
85 end |
86 return true |
87 rescue Exception => ex |
88 return false |
89 end |
90 |
91 # Description : refresh the current web page |
92 # Author : Chandra sekaran |
93 # Arguments : |
94 # page_object : page object |
95 # |
96 def refresh_page(page_object) |
97 page_object.refresh |
98 wait_for_page_load |
99 end |
100 |
101 # Description : function for moving to newly opened browser window |
102 # Author : Chandra sekaran |
103 # |
104 def switch_to_next_window |
105 raise "Number of windows should be two" if @browser.window_handles.size != 2 |
106 window_to_switch = @browser.window_handles.find { |window| window != @browser.window_handle } |
107 @browser.switch_to.window window_to_switch |
108 end |
109 |
110 # Description : closes other browser windows and switches to application main window |
111 # Author : Chandra sekaran |
112 # |
113 def switch_to_application_window |
114 if @browser.window_handles.size > 1 |
115 window_to_close = @browser.window_handle |
116 parent_window = @browser.window_handles.find_all { |window| window != @browser.window_handle } |
117 @browser.switch_to.window window_to_close |
118 puts("Closing window " + @browser.title) |
119 @browser.close |
120 parent_window.each do |window| |
121 @browser.switch_to.window window |
122 end |
123 end |
124 end |
125 |
126 # Description : function for getting all steps under the current running scenario |
127 # Author : Chandra sekaran |
128 # Argument : |
129 # feature : feature object of current running feature file |
130 # Return argument : |
131 # arr_steps : array of steps |
132 # |
133 def get_steps(feature) |
134 arr_steps = [] |
135 feature.feature_elements[$scenario_count].steps.each do |step| |
136 arr_steps << step.name |
137 end |
138 arr_steps |
139 end |
140 |
141 # Description : function for getting the delay (in seconds) between the parallel executions |
142 # Author : Chandra sekaran |
143 # Return argument : delay in seconds |
144 # |
145 def get_execution_delay_time |
146 num_seconds = 0 |
147 if DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "second" |
148 num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i |
149 elsif DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "minute" |
150 num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i * 60 |
151 elsif DELAY_BETWEEN_PARALLEL_THREADS.downcase.include? "hour" |
152 num_seconds = DELAY_BETWEEN_PARALLEL_THREADS.scan(/\d/).join('').to_i * 60 * 60 |
153 end |
154 $log.info "#{NO_OF_PARALLEL_THREADS.to_i * num_seconds}" |
155 [0, 1].include?(NO_OF_PARALLEL_THREADS.to_i) ? 0 : NO_OF_PARALLEL_THREADS.to_i * num_seconds |
156 end |
157 |
158 end |
159 end |
Generated on 2015-05-08 10:40:30 +0530 with SimpleCov-RCov 0.2.3