Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
object_repository/desktop/gem_search.rb | 238 | 114 | 66.39%
|
29.82%
|
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 : Gem Search |
4 *Description : class that holds the Gem page objects and method definitions |
5 *Author : Chandra sekaran |
6 *Creation Date : 24/04/2015 |
7 *Modification Date: |
8 =end |
9 |
10 module CUKES |
11 class RubyGems |
12 include PageObject |
13 include PageUtils |
14 include FileLibrary |
15 |
16 # home page objects |
17 div(:div_header_image, :xpath => "html/body/div/div[1]") |
18 |
19 link(:link_signin, :href => "/sign_in") |
20 text_field(:textfield_email, :id => "session_who") |
21 text_field(:textfield_password, :id => "session_password") |
22 button(:button_sign_in, :class => "form__submit") |
23 link(:link_menu, :class => "header__popup-link") |
24 link(:link_signout, :href => "/sign_out") |
25 text_field(:input_search, :id => "query") |
26 |
27 # gem list page objects |
28 h1(:h1_title, :xpath => "//h1[contains(@class,'page__heading')]") |
29 div(:div_search_result, :class => "l-wrap--b") |
30 |
31 # gem description page objects |
32 text_fields(:textfield_gem_install, :xpath => "//div[@class='gem__code-wrap']/input") |
33 pre(:pre_gemfile, :xpath => "//div[@class='bundler']/pre") |
34 div(:div_gem_version, :class => "versions") |
35 div(:div_gem_runtime_dependencies, :id => "runtime_dependencies") |
36 div(:div_gem_ruby_dependencies, :id => "ruby_dependency") |
37 div(:div_gem_development_dependencies, :id => "development_dependencies") |
38 |
39 # expected_title "RubyGems.org | your community gem host" |
40 |
41 # Description : invoked automatically when the page class object is created |
42 # Author : Chandra sekaran |
43 # |
44 def initialize_page |
45 wait_for_page_load |
46 # has_expected_title? |
47 end |
48 |
49 # Description : sign into the application |
50 # Author : Chandra sekaran |
51 # |
52 def sign_in |
53 click_on(link_signin_element) |
54 wait_for_object(textfield_email_element, "Could not find textfield Email") |
55 self.textfield_email = USER_NAME # "profchan2k15@gmail.com" |
56 self.textfield_password = PASSWORD # "chan123@1" |
57 click_on(button_sign_in_element) |
58 wait_for_page_load |
59 #raise "Error in sign in" if !is_text_present(self, "CHAN90", 120) |
60 $log.success("Sign in successful") |
61 rescue Exception => ex |
62 $log.error("Failure while signing in : #{ex}") |
63 exit |
64 end |
65 |
66 # Description : sign out from the application |
67 # Author : Chandra sekaran |
68 # |
69 def sign_out |
70 click_on(link_menu_element) |
71 click_on(link_signout_element) |
72 #raise "Error in sign out" if !is_text_present(self, "Sign in", 120) |
73 $log.success("Sign out successful") |
74 rescue Exception => ex |
75 $log.error("Failure while signing out : #{ex}") |
76 exit |
77 end |
78 |
79 # Description : searches for the given input gem name |
80 # Author : Chandra sekaran |
81 # Arguments : |
82 # gem_name : name of the gem |
83 # str_data_node : test data root node name |
84 # |
85 def search_for_gem(gem_name = "", str_data_node = "gems") |
86 if gem_name == "" |
87 # the set_scenario_based_datafile method sets the test data content from the given input file name |
88 # present in library/app_specific/datafile_names.rb |
89 # the yml file can be : |
90 # * a local data file - inside the current feature name directory |
91 # * a global data file - inside desktop directory |
92 hash_gem_name = set_scenario_based_datafile(GEM_NAME) |
93 gem_name = hash_gem_name[str_data_node]["gem_name"] |
94 end |
95 wait_for_object(input_search_element, "Could not find search textbox") |
96 self.input_search = gem_name |
97 input_search_element.send_keys(:enter) |
98 rescue Exception => ex |
99 $log.error("Failure while searching for gem '#{gem_name}' : #{ex}") |
100 exit |
101 end |
102 |
103 # Description : compares the gem header name |
104 # Author : Chandra sekaran |
105 # Argument : |
106 # gem_name : name of the gem |
107 # |
108 def compare_heading(gem_name) |
109 wait_for_object(h1_title_element) |
110 expected_heading = "search for #{gem_name}" |
111 actual_heading = h1_title_element.text |
112 raise "The expected heading is #{expected_heading} but actual heading is #{actual_heading}" if actual_heading != expected_heading |
113 wait_for_object(div_search_result_element, "Could not find gem result list") |
114 raise "No gems found for the given gem" if div_search_result_element.text.include?("No gems found") |
115 rescue Exception => ex |
116 $log.error("Failure while comparing Gem header for gem '#{gem_name}' : #{ex}") |
117 exit |
118 end |
119 |
120 # Description : searches for the specific gem and selects it |
121 # Author : Chandra sekaran |
122 # |
123 def fetch_desired_gem |
124 gem_object = "" |
125 gem_name = "" |
126 max = 0 |
127 div_search_result_element.link_elements(:xpath => "./a").each do |parent| |
128 current = parent.paragraph_element(:xpath => "./p").text |
129 current = current.gsub!(',','').to_i if current.include?(',') |
130 if max < current.to_i |
131 max = current.to_i |
132 gem_object = parent.strong_element(:xpath => "./div/h2") |
133 end |
134 end |
135 gem_name = gem_object.text |
136 gem_object.click |
137 gem_name |
138 rescue Exception => ex |
139 $log.error("Failure while getting desired gem : #{ex}") |
140 exit |
141 end |
142 |
143 # Description : fetches the gem details |
144 # Author : Chandra sekaran |
145 # Argument : |
146 # gem : name of the gem |
147 # |
148 def fetch_gem_details(gem) |
149 wait_for_object(h1_title_element) |
150 |
151 gem_name, gem_version = split_gem_and_version(gem) |
152 gem_heading = gem_name + " " + gem_version |
153 raise "The expected value is '#{gem_heading}' but the actual value is '#{h1_title_element.text}'" if h1_title_element.text != gem_heading |
154 |
155 $log.info "Gem Description" |
156 $log.info "\tGem Name : #{h1_title_element.text}" |
157 $log.info "\tGem install : #{textfield_gem_install_elements.last.value}" |
158 $log.info "\tGemfile : #{textfield_gem_install_elements.first.value}" |
159 |
160 fetch_gem_versions |
161 fetch_gem_runtime_dependencies |
162 fetch_gem_ruby_dependencies |
163 fetch_gem_development_dependencies |
164 rescue Exception => ex |
165 $log.error("Failure while fetching Gem details for gem '#{gem_name}' : #{ex}") |
166 exit |
167 end |
168 |
169 # Description : fetches the gem version |
170 # Author : Chandra sekaran |
171 # |
172 def fetch_gem_versions |
173 $log.info "Versions" |
174 fetch_list_items(div_gem_version_element) |
175 end |
176 |
177 # Description : fetches the gem runtime dependencies |
178 # Author : Chandra sekaran |
179 # |
180 def fetch_gem_runtime_dependencies |
181 $log.info "Runtime Dependencies" |
182 fetch_list_items(div_gem_runtime_dependencies_element) |
183 end |
184 |
185 # Description : fetches the gem ruby dependencies |
186 # Author : Chandra sekaran |
187 # |
188 def fetch_gem_ruby_dependencies |
189 $log.info "Ruby Dependency" |
190 fetch_list_items(div_gem_ruby_dependencies_element) |
191 end |
192 |
193 # Description : fetches the gem development dependencies |
194 # Author : Chandra sekaran |
195 # |
196 def fetch_gem_development_dependencies |
197 $log.info "Ruby Dependency" |
198 fetch_list_items(div_gem_development_dependencies_element) |
199 end |
200 |
201 # Description : fetches the text under list of elements |
202 # Author : Chandra sekaran |
203 # Argument : |
204 # parent_element : parent element object |
205 # |
206 def fetch_list_items(parent_element) |
207 if parent_element.exists? && parent_element.visible? |
208 list_elements = "" |
209 if parent_element.div_element(:xpath => "./div[@class='t-list__items']").exists? |
210 list_elements = parent_element.link_elements(:xpath => "./div[@class='t-list__items']/a") |
211 elsif parent_element.ordered_list_element(:xpath => "./ol").exists? |
212 list_elements = parent_element.list_item_elements(:xpath => "./ol/li") |
213 end |
214 list_elements.each do |list| |
215 $log.info "\t #{list.text}" |
216 end |
217 else |
218 $log.info "\t No data found" |
219 end |
220 rescue Exception => ex |
221 $log.error("Failure while fetching gem list items : #{ex}") |
222 exit |
223 end |
224 |
225 # Description : splits gem name and its version from given input string |
226 # Author : Chandra sekaran |
227 # Argument : |
228 # gem : gem name string with version |
229 # Return Arguments : |
230 # gem_name : gem name |
231 # gem_version : gem version |
232 # |
233 def split_gem_and_version(gem) |
234 gem_name = gem.split(" ").first |
235 gem_version = gem.split(" ").last |
236 return gem_name, gem_version |
237 end |
238 end |
239 end |
Generated on 2015-05-08 10:40:30 +0530 with SimpleCov-RCov 0.2.3