Module: Capydriver
- Defined in:
- lib/capydriver.rb
Overview
Need to test Web Pages? Need to test in different Browsers? Even the great IE (puke)? This module helps you do that! Just pass the driver and the configurations and it’s done
Constant Summary collapse
- DRIVERS =
Driver list when adding support to a new driver add here the symbol and the require string
{ poltergeist: 'capybara/poltergeist', selenium: 'selenium-webdriver' }
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#create(driver, browser = nil) ⇒ Object
Creates a new browser with Capybara driver is a mandatory value all the others are driver/browser specific values and should be built according to the driver specification.
-
#login(hash_info) ⇒ Object
Logs the user The page needs to be a valid login page :string_user => username label :string_pass => password label :user => username to use :pass => password to use :string_button => login button info :string_logout => logout button/link info.
-
#logout(string) ⇒ Object
Logout user from current website.
-
#search(hash_info) ⇒ Object
Interact with a search engine :search => searchbar identifier :text => text to search :button => button identifier.
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
11 12 13 |
# File 'lib/capydriver.rb', line 11 def session @session end |
Instance Method Details
#create(driver, browser = nil) ⇒ Object
Creates a new browser with Capybara driver is a mandatory value all the others are driver/browser specific values and should be built according to the driver specification
25 26 27 28 29 30 31 32 33 |
# File 'lib/capydriver.rb', line 25 def create(driver, browser = nil) require_driver driver if driver && browser Capybara.register_driver driver do |drv| Capybara.const_get(driver.capitalize)::Driver.new(drv, browser) end end @session = Capybara::Session.new(driver) end |
#login(hash_info) ⇒ Object
Logs the user The page needs to be a valid login page :string_user => username label :string_pass => password label :user => username to use :pass => password to use :string_button => login button info :string_logout => logout button/link info
44 45 46 47 48 49 50 51 52 |
# File 'lib/capydriver.rb', line 44 def login(hash_info) %w(user pass).each do |key| label, value = "string_#{key}".to_sym, key.to_sym @session.fill_in(hash_info[label], with: hash_info[value]) end @session.click_on(hash_info[:string_button]) @session.has_content?(hash_info[:string_logout]) end |
#logout(string) ⇒ Object
Logout user from current website
57 58 59 60 |
# File 'lib/capydriver.rb', line 57 def logout(string) @session.click_on(string) @session.has_no_content?(string) end |
#search(hash_info) ⇒ Object
Interact with a search engine :search => searchbar identifier :text => text to search :button => button identifier
67 68 69 70 71 |
# File 'lib/capydriver.rb', line 67 def search(hash_info) @session.fill_in(hash_info[:search], with: hash_info[:text]) @session.click_on(hash_info[:button]) @session.has_content?(hash_info[:text]) end |