vanilla_selenium_wrapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 197d87b2f4d52a7b7aae505ba69d605dd1f8379c
4
+ data.tar.gz: d14dd660a8c0758d70989e0357cae0cf31647150
5
+ SHA512:
6
+ metadata.gz: 549f1416c2cdf6274dd6e643680a9dab9baeb812b0ca8f9748d3149e89cc34dd6c77282e5bc1ae014d6cb0674bdb338651c6dfe8e65e5b6a198ab4fed0c3201a
7
+ data.tar.gz: 023702fec4a1297e28b18d4f898ee4c2bd5ef96023176b2cf4ed66298c1aa6156cf4311754326259862671dd5f117477b1bc1dd3d1da0c533860938d6ba24d6c
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at siddharth.pandey@afourtech.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gem 'vanilla_utility_reader', git: 'git@ec2-54-173-216-70.compute-1.amazonaws.com:sid_a4/vanilla_utility_reader.git', :branch => 'master'
5
+
6
+ # Specify your gem's dependencies in vanilla_selenium_wrapper.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 siddharth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # VanillaSeleniumWrapper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vanilla_selenium_wrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vanilla_selenium_wrapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vanilla_selenium_wrapper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vanilla_selenium_wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,646 @@
1
+ module VanillaSeleniumWrapper
2
+ # class PageAction
3
+ module PageAction
4
+
5
+ def launch_selenium_webdriver
6
+ $driver = Selenium::WebDriver.for configuration_reader['browser'].to_sym
7
+ $driver.manage.window.maximize
8
+ end
9
+
10
+
11
+ # get_url :: It opens the browser defined in config file and performs sending the URL and executing it on open web browser
12
+ # Input : URL String eg. www.google.com
13
+ # It can be either passed using configuration file or using the default parameter
14
+ # usage :: create the object of PageAction class
15
+ # $browser = Vanilla::PageAction
16
+ # $browser.get_url("http://www.google.com")
17
+ def get_url(url=nil)
18
+ begin
19
+ if url.to_s.length == 0
20
+ url = get_browser = VanillaUtilityReader::VanillaFileReader::ConfigReader.configuration_reader
21
+ $driver.navigate.to(configuration_reader['url'].to_s)
22
+ else
23
+ $driver.navigate.to(url)
24
+ end
25
+ rescue Exception => e
26
+ raise "Error in getting URL \n Error Message ::"+e.message
27
+ end
28
+ end
29
+
30
+ # forward performs sending forward action to opened browser button
31
+ # usage :: create the object of PageAction class
32
+ # $browser = Vanilla::PageAction
33
+ # $browser.forward
34
+ def forward
35
+ begin
36
+ $driver.navigate.forward
37
+ rescue Exception => e
38
+ raise "Browser navigating forward error \n Error Message :: "+e.message
39
+ end
40
+ end
41
+
42
+ # back performs sending backward action to opened browser button
43
+ # usage :: create the object of PageAction class
44
+ # $browser = Vanilla::PageAction
45
+ # $browser.back
46
+ def back
47
+ begin
48
+ $driver.navigate.back
49
+ rescue Exception => e
50
+ raise "Browser navigating backward error \n Error Message :: "+e.message
51
+ end
52
+ end
53
+
54
+ # close_browser :: closes all browser windows, and quit the selenium session
55
+ # usage :: create the object of PageAction class
56
+ # $browser = Vanilla::PageAction
57
+ # $browser.close_browser
58
+ def close_browser
59
+ #$LOG.info "Inside close browser method"
60
+ begin
61
+ $driver.quit
62
+ rescue Exception => e
63
+ raise "Error in quiting browser and ending session \n Error Message ::" + e.message
64
+ end
65
+ end
66
+
67
+ # close_window :: closes the current browser windows, selenium session is still active
68
+ # usage :: create the object of PageAction class
69
+ # $browser = Vanilla::PageAction
70
+ # $browser.close_window
71
+ def close_window
72
+ begin
73
+ $driver.close
74
+ rescue Exception => e
75
+ raise "Error Close the current window \n Error Message :: "+e.message
76
+ end
77
+ end
78
+
79
+
80
+ # el(element_name) will grab the element from the defined CSV and JSON file
81
+ # custom method too find element
82
+ # O/P :: return the element
83
+ # usage :: Other methods default uses to grab element from the defined object repository
84
+ def el(element_name)
85
+ begin
86
+ # raise "Element name not exist in object repository" unless element_name.class != "Hash" && element_name.length < 0
87
+ element_name.each do |k,v|
88
+ if(k=='class' || k=='css' || k=='id' || k=='xpath' || k=='partial_link_text' || k=='tag_name')
89
+ begin
90
+ $elem = $driver.find_element(k.to_sym,v.to_s)
91
+ rescue Exception => e
92
+ raise "Element not found \n #{element_name} : #{k} => #{v} \n Error Message :: " + e.message
93
+ end
94
+ $elem
95
+ end
96
+ $elem
97
+ end
98
+ $elem
99
+ rescue
100
+ raise "Element not present in object repository"
101
+ end
102
+ end
103
+
104
+ # els(element_name) will grab the element from the defined CSV and JSON file
105
+ # It will return the array of element
106
+ # def els(element_name)
107
+ # element_reader = get_locator(element_name)
108
+ # begin
109
+ # if element_reader.length > 0
110
+ # element_reader.each do |k,v|
111
+ # if(k=='class' || k=='css' || k=='id' || k=='xpath' || k=='partial_link_text' || k=='tag_name')
112
+ # begin
113
+ # $elem = $driver.find_elements(k.to_sym,v.to_s)
114
+ # $elem
115
+ # rescue Exception => e
116
+ # raise "Element not found \n #{element_name} : #{k} => #{v} \n Error Message :: " + e.message
117
+ # end
118
+ # end
119
+ # end
120
+ # $elem
121
+ # else
122
+ # raise "Element not present in object repository"
123
+ # end
124
+ # rescue Exception => e
125
+ # raise "Error in finding the element :: " + e.message
126
+ # end
127
+ # end
128
+
129
+
130
+ # wait_and_find_element: will wait for element
131
+ # I/P :: Parameter is defined "element name" in csv or json file
132
+ # O/P :: return true if element is appears in webpage else it will throw error
133
+ # usage :: create the object of PageAction class
134
+ # $browser = Vanilla::PageAction
135
+ # $browser.wait_and_find_element(element_name)
136
+ def wait_and_find_element(element_name)
137
+ #$LOG.info "Waiting for element #{element_name}"
138
+ begin
139
+ timeout = VanillaUtilityReader::VanillaFileReader::ConfigReader.configuration_reader
140
+ timeout = timeout['wait']
141
+ if timeout == 0
142
+ timeout = 10
143
+ end
144
+ wait_ele = el(element_name)
145
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout ) # seconds
146
+ wait.until { wait_ele }
147
+ rescue Exception => e
148
+ #$LOG.error "Element is not displayed in specific time "+e.message
149
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
150
+ # $webscreenshot = $webscreenshot+1
151
+ raise "Element is not displayed in specific time "+e.message
152
+ end
153
+ end
154
+
155
+
156
+ # element_enabled : It verifies the element is enabled on webpage
157
+ # I/P :: Parameter is defined "element name" in csv or json file
158
+ # O/P :: return true if element is enabled to perform action in webpage else it will throw error
159
+ # usage :: create the object of PageAction class
160
+ # $browser = Vanilla::PageAction
161
+ # $browser.element_enabled(element_name)
162
+ def element_enabled(element_name)
163
+ #$LOG.info "verifing enabled Element #{element_name}"
164
+ begin
165
+ raise "Element not found" unless wait_and_find_element(element_name)
166
+ raise "Element not enabled" unless (expect(el(element_name).enabled?).to eql true)
167
+ rescue Exception => e
168
+ #$LOG.error "Element not Enabled "+ e.message
169
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
170
+ # $webscreenshot = $webscreenshot+1
171
+ raise "Element not Enabled "+ e.message
172
+ end
173
+ end
174
+
175
+
176
+ # click_on_element :: It click on defined element
177
+ # I/P :: Parameter is defined "element name" in csv or json file
178
+ # O/P :: It clicks on element
179
+ # usage :: create the object of PageAction class
180
+ # $browser = Vanilla::PageAction
181
+ # $browser.click_on_element(element_name)
182
+ def click_on_element(element_name)
183
+ #$LOG.info "clicking on element #{element_name} "
184
+ begin
185
+ wait_and_find_element element_name
186
+ click_ele = el(element_name)
187
+ click_ele.click
188
+ rescue Exception => e
189
+ #$LOG.error "Can't click on element "+ e.message
190
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
191
+ # $webscreenshot = $webscreenshot+1
192
+ raise "Can't click on element test "+ e.message
193
+ end
194
+ end
195
+
196
+
197
+ # delete_all_cookies :: It delete all cookies from browser
198
+ # O/P :: delete all cookies
199
+ # usage :: create the object of PageAction class
200
+ # $browser = Vanilla::PageAction
201
+ # $browser.delete_all_cookie
202
+ def delete_all_cookies
203
+ #$LOG.info "deleting all cookies"
204
+ begin
205
+ $driver.manage.delete_all_cookies
206
+ rescue Exception => e
207
+ #$LOG.error "error in deleting cookies :: " +e.message
208
+ raise "error in deleting cookies :: " +e.message
209
+ end
210
+ end
211
+
212
+ # delete_cookie :: Delete particular cookie in Selenium session browser
213
+ # I/P :: parameter should be the name of cookie to be deleted
214
+ # O/P :: It deletes particular from browser
215
+ # usage :: create the object of PageAction class
216
+ # $browser = Vanilla::PageAction
217
+ # $browser.delete_cookie(cookie_name)
218
+ def delete_cookie(name)
219
+ #$LOG.info "deleting cookie #{name}"
220
+ begin
221
+ $driver.manage.delete_cookie name
222
+ rescue Exception => e
223
+ #$LOG.error "error in deleting cookie #{name} "+e.message
224
+ raise "Error in deleting cookie #{name} "+e.message
225
+ end
226
+ end
227
+
228
+ # add_cookie :: add cookie in browser session
229
+ # I/P :: (key,value) cookie key and value is added to brower session
230
+ # O/P :: adds the cookie to browser session
231
+ # usage :: create the object of PageAction class
232
+ # $browser = Vanilla::PageAction
233
+ # $browser.add_cookie(key,value)
234
+ def add_cookie(key,value)
235
+ #$LOG.info "adding cookie with key => #{key} and value => #{value}"
236
+ begin
237
+ $driver.manage.add_cookie(:name => "#{key}", :value => "#{value}")
238
+ rescue Exception => e
239
+ #$LOG.error "Add Cookie can't be completed "+e.message
240
+ raise "Add Cookie can't be completed "+e.message
241
+ end
242
+ end
243
+
244
+ # all_cookies :: get all cookies in current session
245
+ # O/P :: Returns the array of cookies
246
+ # usage :: create the object of PageAction class
247
+ # $browser = Vanilla::PageAction
248
+ # $browser.all_cookies
249
+ def all_cookies
250
+ $LOG.info "Return all cookies"
251
+ begin
252
+ $driver.manage.all_cookies
253
+ rescue Exception => e
254
+ $LOG.error "get all cookies can't be completed\nerror :: "+e.message
255
+ raise "get all cookies can't be completed \nerror :: "+e.message
256
+ end
257
+ end
258
+
259
+
260
+
261
+ # drag_and_drop :: It drags the element from current location to target location
262
+ # I/P :: parameter(source_element) :: element name, Defined in object repository (csv or json),
263
+ # parameter(target_element) :: element name, Defined in object repository (csv or json)
264
+ # O/P :: drags the element name
265
+ # usage :: create the object of PageAction class
266
+ # $browser = Vanilla::PageAction
267
+ # $browser.drag_and_drop(source_element, target_element)
268
+ def drag_and_drop(source_element_, target_element)
269
+ #$LOG.info "draging and droping the element Source : #{source_element_} and Target : #{target_element}"
270
+ begin
271
+ wait_and_find_element(source_element_)
272
+ wait_and_find_element(target_element)
273
+ element = el(source_element_)
274
+ target = el(target_element)
275
+ $driver.action.drag_and_drop(element, target).perform
276
+ rescue Exception => e
277
+ #$LOG.error "Error in drag and drop \n source element :: #{source_element_} \n target element #{target_element}"
278
+ #$LOG.error "Error Message :: " +e.message
279
+ #$driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
280
+ #$webscreenshot = $webscreenshot+1
281
+ raise "Error in drag and drop \n source element :: #{source_element_} \n target element #{target_element} \n " + e.message
282
+ end
283
+ end
284
+
285
+
286
+ # get_text :: ets the text value of the current element
287
+ # I/P :: Parameter is defined "element name" in csv or json file
288
+ # O/P :: gets the text from the element
289
+ # usage :: create the object of PageAction class
290
+ # $browser = Vanilla::PageAction
291
+ # $browser.get_text(element_name)
292
+ def get_text(element_name)
293
+ #$LOG.info "getting text of an element #{element_name}"
294
+ begin
295
+ wait_and_find_element(element_name)
296
+ ele_get_text = el(element_name)
297
+ ele_get_text.text
298
+ rescue Exception => e
299
+ #$LOG.error "Error getting text value of element name : #{element_name} "+e.message
300
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
301
+ # $webscreenshot = $webscreenshot+1
302
+ raise "Error getting text value of element name : #{element_name} "+e.message
303
+ end
304
+ end
305
+
306
+ # clear_text :: clear value of text field or text area element name and text value
307
+ # I/P :: Parameter is defined "element name" in csv or json file
308
+ # Output :: clear value of text field or text area
309
+ # usage :: create the object of PageAction class
310
+ # $browser = Vanilla::PageAction
311
+ # $browser.clear_text(element_name)
312
+ def clear_text(element_name)
313
+ #$LOG.info "clear value of text field or text area : #{element_name}"
314
+ wait_and_find_element(element_name)
315
+ begin
316
+ wait_and_find_element element_name
317
+ clear_value = el element_name
318
+ clear_value.clear
319
+ rescue Exception => e
320
+ #$LOG.error "Unable to clear value of text field or text area : #{element_name} "+e.message
321
+ #$driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
322
+ #$webscreenshot = $webscreenshot+1
323
+ raise "Unable to clear value of text field or text area : #{element_name} "+e.message
324
+ end
325
+ end
326
+
327
+ # send_keys_text :: sends the text value of text field or text area element name
328
+ # Input :: parameter(element name) defined in JSON / CSV file
329
+ # parameter(text) send the text value in text field and text area
330
+ # Output :: type the text value in text field and text area
331
+ # usage :: create the object of PageAction class
332
+ # $browser = Vanilla::PageAction
333
+ # $browser.send_keys_text(element_type, text)
334
+ def send_keys_text(element_name, text)
335
+ #$LOG.info "sending values of element name : #{element_name} and text_value : #{text} "
336
+ wait_and_find_element(element_name)
337
+ begin
338
+ wait_and_find_element element_name
339
+ send_value = el element_name
340
+ send_value.send_keys text
341
+ rescue Exception => e
342
+ #$LOG.error "error in sending values of element name : #{element_name} and text_value : #{text} "+e.message
343
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
344
+ # $webscreenshot = $webscreenshot+1
345
+ raise "error in sending values element name : #{element_name} and text_value : #{text} "+e.message
346
+ end
347
+ end
348
+
349
+ # element_location(element_type) :: gets the element location
350
+ # I/P :: Parameter is defined "element name" in csv or json file
351
+ # Output :: Gets the element location
352
+ # usage :: create the object of PageAction class
353
+ # $browser = Vanilla::PageAction
354
+ # $browser.element_location(element_name)
355
+ def element_location(element_name)
356
+ #$LOG.info "getting element location #{element_name}"
357
+ begin
358
+ wait_and_find_element(element_name)
359
+ el_loc = el element_name
360
+ el_loc.location
361
+ rescue Exception => e
362
+ #$LOG.error "Error getting element location of element name : #{element_name} "+e.message
363
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
364
+ # $webscreenshot = $webscreenshot+1
365
+ raise "Error getting element location of element name : #{element_name} "+e.message
366
+ end
367
+ end
368
+
369
+
370
+ # location_scroll(element_type) :: scroll to element location
371
+ # I/P :: Parameter is defined "element name" in csv or json file
372
+ # Output :: scroll to location
373
+ # usage :: create the object of PageAction class
374
+ # $browser = Vanilla::PageAction
375
+ # $browser.location_scroll(element_name)
376
+ def location_scroll(element_name)
377
+ #$LOG.info "getting location scroll for element : #{element_name}"
378
+ begin
379
+ wait_and_find_element element_name
380
+ loc_scr = el element_name
381
+ loc_scr.location_once_scrolled_into_view
382
+ rescue Exception => e
383
+ #$LOG.error "Error in scrolling to location of element name : #{element_name} " +e.message
384
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
385
+ # $webscreenshot = $webscreenshot+1
386
+ raise "Error in scrolling to location of element name : #{element_name} " +e.message
387
+ end
388
+ end
389
+
390
+ # element_size :: get the size of element
391
+ # I/P :: Parameter is defined "element name" in csv or json file
392
+ # Output :: Gets the size of element
393
+ # usage :: create the object of PageAction class
394
+ # $browser = Vanilla::PageAction
395
+ # $browser.element_size(element_name)
396
+ def element_size(element_name)
397
+ #$LOG.info "getting element size of #{element_name}"
398
+ begin
399
+ wait_and_find_element element_name
400
+ el_size = el element_name
401
+ el_size.size
402
+ rescue Exception => e
403
+ #$LOG.error "Error in size of element of element name : #{element_name} \n Error Message :: "+e.message
404
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
405
+ # $webscreenshot = $webscreenshot+1
406
+ raise "Error in size of element of element name : #{element_name}\n Error Message ::"+e.message
407
+ end
408
+ end
409
+
410
+ # element_displayed :: The element is displayed on web page
411
+ # I/P :: Parameter is defined "element name" in csv or json file
412
+ # Output :: return element is displayed on web page
413
+ # usage :: create the object of PageAction class
414
+ # $browser = Vanilla::PageAction
415
+ # $browser.element_displayed(element_name)
416
+ def element_displayed(element_name)
417
+ #$LOG.info "verify element displayed in current page #{element_name}"
418
+ begin
419
+ wait_and_find_element element_name
420
+ el_disp = el element_name
421
+ el_disp.display?
422
+ rescue Exception => e
423
+ #$LOG.error "error in displaying Element of element name : #{element_name} "+e.message
424
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
425
+ # $webscreenshot = $webscreenshot+1
426
+ raise "error in displaying Element of element name : #{element_name}"+e.message
427
+ end
428
+ end
429
+
430
+ # element_attribute :: Get the attribute of element
431
+ # I/P :: Parameter is defined "element name" in csv or json file
432
+ # Output :: return the attribute of element
433
+ # usage :: create the object of PageAction class
434
+ # $browser = Vanilla::PageAction
435
+ # $browser.element_attribute(element_name, attribute_type)
436
+ def element_attribute(element_name, attribute_type)
437
+ #$LOG.info "fetching attribute of Element \n element name : #{element_name} & Attribute type : #{attribute_type} "
438
+ begin
439
+ wait_and_find_element element_name
440
+ el_attribute = el element_name
441
+ el_attribute.attribute(attribute_type)
442
+ rescue Exception => e
443
+ #$LOG.error "error in fetching attribute of Element \n element name : #{element_name} & Attribute type : #{attribute_type} "+e.message
444
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
445
+ # $webscreenshot = $webscreenshot+1
446
+ raise "error in fetching Element"+e.message
447
+ end
448
+ end
449
+
450
+ # value :: Get the value of element
451
+ # I/P :: Parameter is defined "element name" in csv or json file
452
+ # O/P :: Get the element value
453
+ # usage :: create the object of PageAction class
454
+ # $browser = Vanilla::PageAction
455
+ # $browser.value(element_name)
456
+ def value element_name
457
+ begin
458
+ el_attribute = el element_name
459
+ el_attribute.attribute('value')
460
+ rescue Exception => e
461
+ #$LOG.error "error in getting element value \n element name : #{element_name} "+e.message
462
+ raise "error in getting element value \n element name : #{element_name} "+e.message
463
+ end
464
+ end
465
+
466
+ # move_to element_name, right_by = nil, down_by = nil :: move the element from one location to other
467
+ # Input :: Element_name => element name defined in JSON / CSV file, right_by => value to shift right, down_by => value to move
468
+ # Output :: Move the element
469
+ # usage :: create the object of PageAction class
470
+ # $browser = Vanilla::PageAction
471
+ # $browser.move_to(element_name, right_by = nil, down_by = nil)
472
+ def move_to element_name, right_by = nil, down_by = nil
473
+ begin
474
+ $driver.action.move_to(el(element_name), right_by, down_by).perform
475
+ rescue Exception => e
476
+ #$LOG.error "error in moving element \n element name : #{element_name}, right: #{right_by} and down: #{down_by} "+e.message
477
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
478
+ # $webscreenshot = $webscreenshot+1
479
+ raise "error in moving element \n element name : #{element_name}, right: #{right_by} and down: #{down_by} "+e.message
480
+ end
481
+ end
482
+
483
+ # double_click :: double clicks on element
484
+ # I/P :: Parameter is defined "element name" in csv or json file
485
+ # Output :: double clicks on element
486
+ # usage :: create the object of PageAction class
487
+ # $browser = Vanilla::PageAction
488
+ # $browser.double_click(element_name)
489
+ def double_click(element_name)
490
+ begin
491
+ $driver.action.double_click(el(element_name)).perform
492
+ rescue Exception => e
493
+ #$LOG.error "error in perform double click on element \n element name : #{element_name} "+e.message
494
+ $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
495
+ $webscreenshot = $webscreenshot+1
496
+ raise "error in perform double click on element \n element name : #{element_name} "+e.message
497
+ end
498
+ end
499
+
500
+ # select:: Select the element, can be used with checkbox or radio
501
+ # Input :: Element_name => element name defined in JSON / CSV file
502
+ # Output :: select the element
503
+ # usage :: create the object of PageAction class
504
+ # $browser = Vanilla::PageAction
505
+ # $browser.select(element_name)
506
+ def select(element_name)
507
+ begin
508
+ el(element_name).click
509
+ rescue Exception => e
510
+ #$LOG.error "error in selecting element \n element name : #{element_name} "+e.message
511
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
512
+ # $webscreenshot = $webscreenshot+1
513
+ raise "error in selecting element \n element name : #{element_name} "+e.message
514
+ end
515
+ end
516
+
517
+ # checkbox_checked(element_name, be_selected=true) :: selecting and verifying check box is selected
518
+ # Input :: Element_name => element name defined in JSON / CSV file
519
+ # Output :: true or false
520
+ # usage :: create the object of PageAction class
521
+ # $browser = Vanilla::PageAction
522
+ # $browser.checkbox_checked(element_name, be_selected=true)
523
+ def selected?(element_name)
524
+ el(element_name).selected?
525
+ end
526
+
527
+ # checkbox_checked(element_name, be_selected=true) :: selecting and verifying check box is selected
528
+ # Input :: Element_name => element name defined in JSON / CSV file
529
+ # Output :: true or false
530
+ def checkbox_checked(element_name, be_selected=true)
531
+ begin
532
+ select_check = select(element_name)
533
+ select_check unless be_selected == selected?(element_name)
534
+ rescue Exception => e
535
+ #$LOG.error "error in selecting check box on element \n element name : #{element_name} "+e.message
536
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
537
+ # $webscreenshot = $webscreenshot+1
538
+ raise "error in selecting check box on element \n element name : #{element_name} "+e.message
539
+ end
540
+ end
541
+
542
+ # Select options by visible text, index or value.
543
+ #
544
+ # When selecting by :text, selects options that display text matching the argument. That is, when given "Bar" this
545
+ # would select an option like:
546
+ #
547
+ # <option value="foo">Bar</option>
548
+ #
549
+ # When selecting by :value, selects all options that have a value matching the argument. That is, when given "foo" this
550
+ # would select an option like:
551
+ #
552
+ # <option value="foo">Bar</option>
553
+ #
554
+ # When selecting by :index, selects the option at the given index. This is done by examining the "index" attribute of an
555
+ # element, and not merely by counting.
556
+ #
557
+ # @param [:text, :index, :value] how How to find the option
558
+ # @param [String] what What value to find the option by.
559
+ #
560
+
561
+ # how can be :text, :index, :value
562
+
563
+
564
+ # Usage ::
565
+ # element_name = company_dropdown
566
+ # dropdown should be selected by "value"
567
+ # value is "afour"
568
+ # $browser = Vanilla::PageAction
569
+ # $browser.select_option('company_dropdown', :value, 'afour')
570
+ def select_option(element_name, how=nil, what=nil)
571
+ begin
572
+ wait_and_find_element(element_name)
573
+ el(element_name).click if how.nil?
574
+ Selenium::WebDriver::Support::Select.new(el(element_name)).select_by(how, what)
575
+ rescue Exception => e
576
+ #$LOG.error "error in dropdown select option \n element name : #{element_name}, using #{how}, and #{what} "+e.message
577
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
578
+ # $webscreenshot = $webscreenshot+1
579
+ raise "error in dropdown select option \n element name : #{element_name}, using #{how}, and #{what} "+e.message
580
+ end
581
+ end
582
+
583
+ # refresh :: it refresh current web page
584
+ # O/P :: refresh current web page, with current URL
585
+ # usage :: create the object of PageAction class
586
+ # $browser = Vanilla::PageAction
587
+ # $browser.get_text(element_name)
588
+ def refresh
589
+ $driver.refresh
590
+ end
591
+
592
+ # switch_frame :: it switch the frame to given frame id or index
593
+ # I/P :: parameter(frame_name) : it requires the frame name or frame id
594
+ # O/P :: Switch to the given frame else return the error message
595
+ # usage :: create the object of PageAction class
596
+ # $browser = Vanilla::PageAction
597
+ # $browser.switch_frame(frame_name)
598
+ def switch_frame(frame_name)
599
+ begin
600
+ $driver.switch_to.frame frame_name
601
+ rescue Exception => e
602
+ #$LOG.error " frame_name : #{frame_name} "+e.message
603
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
604
+ # $webscreenshot = $webscreenshot+1
605
+ raise "\n frame_name : #{frame_name} "+e.message
606
+ end
607
+ end
608
+
609
+ # switch_default :: switches back to default frame
610
+ # O/P :: Switch to the default frame
611
+ # usage :: create the object of PageAction class
612
+ # $browser = Vanilla::PageAction
613
+ # $browser.switch_default
614
+ def switch_default
615
+ begin
616
+ $driver.switch_to.default_content
617
+ rescue Exception => e
618
+ #$LOG.error " frame_name : #{frame_name} "+e.message
619
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
620
+ # $webscreenshot = $webscreenshot+1
621
+ raise "\n frame_name : #{frame_name} "+e.message
622
+ end
623
+ end
624
+
625
+
626
+ # title :: It verify the title
627
+ # I/P :: it takes input as expected title
628
+ # O/P :: return true if page title matches with expected title else return false
629
+ # Information :: This method uses a custom made rspec matchers
630
+ # usage :: create the object of PageAction class
631
+ # $browser = Vanilla::PageAction
632
+ # $browser.title(expected_title)
633
+ def title(expected_title)
634
+ #$LOG.info "Verifying the expected title #{expected_title}"
635
+ #$driver.title
636
+ begin
637
+ expect($driver.title.to_s).to eq(expected_title)
638
+ rescue Exception => e
639
+ #$LOG.error "Error in getting the expected title #{expected_title} "+e.message
640
+ # $driver.save_screenshot("log/webscreenshot/webScreenshot_#{$webscreenshot}.png")
641
+ # $webscreenshot = $webscreenshot+1
642
+ raise "Error in getting the expected title #{expected_title} "+e.message
643
+ end
644
+ end
645
+ end
646
+ end
@@ -0,0 +1,29 @@
1
+ # module CreateDriver
2
+ # # Selenium::WebDriver::Firefox::Binary.path='C:\Program Files\Mozilla Firefox\firefox.exe'
3
+ # def page_driver
4
+ # #@driver = Selenium::WebDriver.for :firefox
5
+ # #begin
6
+ # # brow = INITIALIZATION_COMPONENTS['browser']
7
+ # # $LOG.info "Initializing the browser #{brow}"
8
+ # # @driver = Selenium::WebDriver.for brow.to_sym
9
+ # get_browser = VanillaUtilityReader::VanillaFileReader::ConfigReader.configuration_reader
10
+ # puts get_browser['browser'].to_sym
11
+ # $driver = Selenium::WebDriver.for get_browser['browser'].to_sym
12
+ # #$driver = Selenium::WebDriver.for :firefox
13
+ # # $LOG.info "Browser window maximized"
14
+ # $driver.manage.window.maximize
15
+ # #rescue Exception => e
16
+ # # $LOG.error "Not able to launch #{brow} Error Message :: "+e.message
17
+ # # raise "Not able to launch #{brow} Error Message :: "+e.message
18
+ # #end
19
+ #
20
+ # end
21
+ #
22
+ # def driver
23
+ # $driver
24
+ # end
25
+ #
26
+ # def launch_selenium_driver
27
+ # page_driver
28
+ # end
29
+ # end
@@ -0,0 +1,3 @@
1
+ module VanillaSeleniumWrapper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ # require 'vanilla_selenium_wrapper/version'
2
+
3
+
4
+
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'yaml'
8
+ require 'rspec'
9
+ require 'cucumber'
10
+ require 'rake'
11
+ require 'selenium-webdriver'
12
+ require 'log4r'
13
+ require 'vanilla_utility_reader'
14
+ require 'vanilla_utility_reader/file_utility/config_reader'
15
+ require 'vanilla_utility_reader/file_utility/page_repo_reader'
16
+ require 'vanilla_utility_reader/file_utility/object_reader'
17
+ include VanillaUtilityReader
18
+ include VanillaUtilityReader::VanillaFileReader
19
+ include VanillaUtilityReader::VanillaFileReader::ConfigReader
20
+ include VanillaUtilityReader::VanillaFileReader::PageRepoReader
21
+
22
+
23
+ # require File.dirname(__FILE__) + '/vanilla_selenium_wrapper/driver/launch_driver'
24
+ #
25
+ # include CreateDriver
26
+ require File.dirname(__FILE__) + '/vanilla_selenium_wrapper/actions/page_actions'
27
+ include VanillaSeleniumWrapper
28
+ include VanillaSeleniumWrapper::PageAction
29
+ include PageAction
30
+
31
+
32
+
33
+
34
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vanilla_selenium_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vanilla_selenium_wrapper"
8
+ spec.version = VanillaSeleniumWrapper::VERSION
9
+ spec.authors = ["siddharth"]
10
+ spec.email = ["siddharth.pandey@afourtech.com"]
11
+
12
+ spec.summary = "Contains the selenium wrappers"
13
+ spec.description = "this gem contains the selenium wrapper"
14
+ spec.homepage = "http://afourtech.com/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_development_dependency 'selenium-webdriver', '~> 2.53'
27
+ spec.add_development_dependency 'cucumber', '~> 2.4'
28
+ spec.add_development_dependency 'log4r', '~> 1.1'
29
+ spec.add_development_dependency 'json', '~> 2.0'
30
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vanilla_selenium_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - siddharth
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.53'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.53'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: log4r
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ description: this gem contains the selenium wrapper
112
+ email:
113
+ - siddharth.pandey@afourtech.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - CODE_OF_CONDUCT.md
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/vanilla_selenium_wrapper.rb
124
+ - lib/vanilla_selenium_wrapper/actions/page_actions.rb
125
+ - lib/vanilla_selenium_wrapper/driver/launch_driver.rb
126
+ - lib/vanilla_selenium_wrapper/version.rb
127
+ - vanilla_selenium_wrapper.gemspec
128
+ homepage: http://afourtech.com/
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.8
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Contains the selenium wrappers
152
+ test_files: []