Module: Praline

Defined in:
lib/praline.rb

Overview

Author:

  • Antoine d’Otreppe

Instance Method Summary collapse

Instance Method Details

#browserSelenium::WebDriver::Driver

Get the WebDriver itself, for in-depth manipulation

Returns:

  • (Selenium::WebDriver::Driver)

    the driver



76
77
78
# File 'lib/praline.rb', line 76

def browser
    Praline::browser
end

#follow(link_text) ⇒ Object

Follow the specified link

Parameters:

  • link_text (String)

    the text of the link to follow



64
65
66
# File 'lib/praline.rb', line 64

def follow(link_text)
    Praline::browser.find_element(:link, link_text).click
end

#h1String

Get the text of the <h1> of the current page. Will fail if there are several such tags

Returns:

  • (String)

    the text of the single <h1> tag of the current page



49
50
51
# File 'lib/praline.rb', line 49

def h1
    Praline::browser.find_element(:xpath, "//h1")
end

#input(name, value) ⇒ Object

Fill an input with the given text. Also works with <select> and checkbox elements

Parameters:

  • name (String)

    the html name attribute of the target input

  • value (String)

    the text to be put



36
37
38
# File 'lib/praline.rb', line 36

def input(name, value)
    Praline::browser.find_element(:name, name).send_keys(value)
end

#kill_browserObject

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



82
83
84
# File 'lib/praline.rb', line 82

def kill_browser
    Praline::kill_browser
end

#open(url) ⇒ Object

Load the given URL in the browser

Parameters:

  • url (String)

    the url to open



28
29
30
# File 'lib/praline.rb', line 28

def open(url)
    Praline::browser.get(url)
end

#options(select_name) ⇒ Array

Get the options’ text from a specified select

Parameters:

  • select_name (String)

    name of the select you want to poll

Returns:

  • (Array)

    array of the text values of the options in this select



56
57
58
59
60
# 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) ⇒ Object

Submit the specified form

Parameters:

  • form_name (String)

    the html name of the form to submit



70
71
72
# File 'lib/praline.rb', line 70

def submit(form_name)
    Praline::browser.find_element(:name, form_name).submit
end

#titleString

Get the current page title

Returns:

  • (String)

    the contents of the <title> tag of the current page



42
43
44
# File 'lib/praline.rb', line 42

def title
    Praline::browser.title
end