module Praline

@author Antoine d’Otreppe

Private Class Methods

browser() click to toggle source
# File lib/praline.rb, line 88
def self.browser
    if @browser.nil?
        @browser = Selenium::WebDriver.for(:firefox)
    end
    
    @browser
end
kill_browser() click to toggle source
# File lib/praline.rb, line 96
def self.kill_browser
    if not @browser.nil?
        @browser.quit
        @browser = nil
    end
end

Public Instance Methods

browser() click to toggle source

Get the WebDriver itself, for in-depth manipulation @return [Selenium::WebDriver::Driver] the driver

# File lib/praline.rb, line 76
def browser
    Praline::browser
end
follow(link_text) click to toggle source

Follow the specified link @param [String] link_text the text of the link to follow

# File lib/praline.rb, line 64
def follow(link_text)
    Praline::browser.find_element(:link, link_text).click
end
h1() click to toggle source

Get the text of the <h1> of the current page. Will fail if there are several such tags @return [String] the text of the single <h1> tag of the current page

# File lib/praline.rb, line 49
def h1
    Praline::browser.find_element(:xpath, "//h1")
end
input(name, value) click to toggle source

Fill an input with the given text. Also works with <select> and checkbox elements @param [String] name the html name attribute of the target input @param [String] value the text to be put

# File lib/praline.rb, line 36
def input(name, value)
    Praline::browser.find_element(:name, name).send_keys(value)
end
kill_browser() click to toggle source

Kill the browser. Call this when you are done with your script

# File lib/praline.rb, line 82
def kill_browser
    Praline::kill_browser
end
open(url) click to toggle source

Load the given URL in the browser @param [String] url the url to open

# File lib/praline.rb, line 28
def open(url)
    Praline::browser.get(url)
end
options(select_name) click to toggle source

Get the options’ text from a specified select @param [String] select_name name of the select you want to poll @return [Array] array of the text values of the options in this select

# File lib/praline.rb, line 56
def options(select_name)
    select = Praline::browser.find_element(:name, select_name)
    options = select.find_elements(:tag_name, 'option')
    options.map {|option| option.text }
end
submit(form_name) click to toggle source

Submit the specified form @param [String] form_name the html name of the form to submit

# File lib/praline.rb, line 70
def submit(form_name)
    Praline::browser.find_element(:name, form_name).submit
end
title() click to toggle source

Get the current page title @return [String] the contents of the <title> tag of the current page

# File lib/praline.rb, line 42
def title
    Praline::browser.title
end