Class: Scrubyt::NavigationActions

Inherits:
Object
  • Object
show all
Defined in:
lib/scrubyt/core/navigation/navigation_actions.rb

Overview

Describing actions which interact with the page

This class contains all the actions that are used to navigate on web pages; first of all, fetch for downloading the pages - then various actions like filling textfields, submitting formst, clicking links and more

Constant Summary collapse

KEYWORDS =

These are reserved keywords - they can not be the name of any pattern since they are reserved for describing the navigation

['fetch',
'fill_textfield',
'fill_textarea',
'submit',
'click_link',
'click_image_map',
'select_option',
'check_checkbox',
'check_radiobutton',
'end']

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNavigationActions

Returns a new instance of NavigationActions.



22
23
24
25
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 22

def initialize
    @@current_form = nil
    FetchAction.new
end

Class Method Details

.check_checkbox(checkbox_name) ⇒ Object



57
58
59
60
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 57

def self.check_checkbox(checkbox_name)
  lookup_form_for_tag('input','checkbox',checkbox_name, '')
  @@current_form.checkboxes.name(checkbox_name).check
end

.check_radiobutton(checkbox_name, index = 0) ⇒ Object



62
63
64
65
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 62

def self.check_radiobutton(checkbox_name, index=0)
  lookup_form_for_tag('input','radiobutton',checkbox_name, '',index)
  @@current_form.radiobuttons.name(checkbox_name)[index].check
end

.click_image_map(index = 0) ⇒ Object



93
94
95
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 93

def self.click_image_map(index=0)
  FetchAction.click_image_map(index)
end

Click the link specified by the text ((delegate it to NavigationActions)



89
90
91
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 89

def self.click_link(link_spec,index=0)
  FetchAction.click_link(link_spec,index)
end

.fetch(*args) ⇒ Object

Fetch the document



69
70
71
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 69

def self.fetch(*args)
  FetchAction.fetch(*args)
end

.fill_textarea(textarea_name, text) ⇒ Object

Action to fill a textarea with text



43
44
45
46
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 43

def self.fill_textarea(textarea_name, text)
  lookup_form_for_tag('textarea','textarea',textarea_name,text)
  eval("@@current_form['#{textarea_name}'] = '#{text}'")
end

.fill_textfield(textfield_name, query_string) ⇒ Object

Action to fill a textfield with a query string

parameters

textfield_name - the name of the textfield (e.g. the name of the google search textfield is ‘q’

query_string - the string that should be entered into the textfield



36
37
38
39
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 36

def self.fill_textfield(textfield_name, query_string)
  lookup_form_for_tag('input','textfield',textfield_name,query_string)
  eval("@@current_form['#{textfield_name}'] = '#{query_string}'")
end

.get_current_doc_urlObject



101
102
103
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 101

def self.get_current_doc_url
  FetchAction.get_current_doc_url
end

.get_host_nameObject



105
106
107
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 105

def self.get_host_name
  FetchAction.get_host_name
end

.get_hpricot_docObject



97
98
99
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 97

def self.get_hpricot_doc
  FetchAction.get_hpricot_doc
end

.select_option(selectlist_name, option) ⇒ Object

Action for selecting an option from a dropdown box



50
51
52
53
54
55
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 50

def self.select_option(selectlist_name, option)
  lookup_form_for_tag('select','select list',selectlist_name,option)
  select_list = @@current_form.fields.find {|f| f.name == selectlist_name}
  searched_option = select_list.options.find{|f| f.text.strip == option}
  searched_option.click
end

.submit(index = nil, type = nil) ⇒ Object

Submit the current form (delegate it to NavigationActions)



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/scrubyt/core/navigation/navigation_actions.rb', line 74

def self.submit(index=nil, type=nil)
  if index == nil
    FetchAction.submit(@@current_form)
  #----- added by [email protected] -----
  elsif index.class == String
    button = @@current_form.buttons.detect{|b| b.name == index}
    FetchAction.submit(@@current_form, button,type)
  #-----------------------------------------
  else
    FetchAction.submit(@@current_form, @@current_form.buttons[index])
  end
end