Module: Navigation

Instance Method Summary collapse

Methods included from Utilities

#get, #make_user, #random_percentage, #set, #snake_case

Instance Method Details

#doc_searchObject



17
18
19
20
21
22
23
24
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 17

def doc_search
  visit DocumentSearch do |search|
    search.close_parents
    search.document_id.set @document_id
    search.search
    search.open_doc @document_id
  end
end

#fill_out(page, *fields) ⇒ Object Also known as: fill_in

Use in the #create method of your data objects for filling out fields. This method eliminates the need to write repetitive lines of code, with one line for every field needing to be filled in.

Requirement: The field method name and the class instance variable must be the same!



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 42

def fill_out(page, *fields)
  methods={
      'Watir::TextField' => lambda{|p, f| p.send(f).fit(get f)},
      'Watir::Select'    => lambda{|p, f| p.send(f).pick!(get f)},
      'Watir::Radio'     => lambda{|p, f| p.send(f, get(f)) unless get(f)==nil },
      'Watir::CheckBox'  => lambda{|p, f| p.send(f).fit(get f) }
  }
  fields.shuffle.each do |field|
    # TODO: Someday see if there's a way to fix things so this rescue isn't necessary...
    # It's here because the radio button "element" definitions are *actions* that
    # require a parameter, so just sending the method to the page
    # is not going to work.
    begin
      key = page.send(field).class.to_s
    rescue NoMethodError
      key = 'Watir::Radio'
    end
    methods[key].call(page, field)
  end
end

#fill_out_item(name, page, *fields) ⇒ Object

Same as the above method, but used with methods that take a parameter to identify the target element…



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 66

def fill_out_item(name, page, *fields)
  methods={
      'Watir::TextField' => lambda{|n, p, f| p.send(f, n).fit(get f)},
      'Watir::Select'    => lambda{|n, p, f| p.send(f, n).pick!(get f)},
      'Watir::Radio'     => lambda{|n, p, f| p.send(f, n, get(f)) unless get(f)==nil },
      'Watir::CheckBox'  => lambda{|n, p, f| p.send(f, n).fit(get f) }
  }
  fields.shuffle.each do |field|
    # TODO: Someday see if there's a way to fix things so this rescue isn't necessary...
    # It's here because the radio button "element" definitions are *actions* that
    # require a parameter, so just sending the method to the page
    # is not going to work.
    begin
      key = page.send(field, name).class.to_s
    rescue NoMethodError
      key = 'Watir::Radio'
    end
    methods[key].call(name, page, field)
  end
end

#on_document?(doc_header) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 9

def on_document?(doc_header)
  begin
    on(DocumentHeader).document_id==@document_id && @browser.frm.div(id: 'headerarea').h1.text==doc_header
  rescue Watir::Exception::UnknownObjectException, Selenium::WebDriver::Error::StaleElementReferenceError
    false
  end
end

#on_page?(element) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 26

def on_page? element
  begin
    element.exist?
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
    false
  end
end

#open_document(doc_header) ⇒ Object



5
6
7
# File 'lib/kuality-coeus/data_objects/navigation.rb', line 5

def open_document doc_header
  doc_search unless on_document?(doc_header)
end