Class: GenericTest::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/generic_test/page.rb

Overview

Represents a web page state at a particular point of time

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ Page

Store state of page when it is loaded

Parameters:

  • browser (Watir::Browser)

    Watir browser



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generic_test/page.rb', line 19

def initialize(browser)
  self.emails, self.links = browser.links.partition do |link|
    link.href.start_with?('mailto:')
  end
  links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') || link.href.include?('tel:') }
  emails.collect! { |link| link.href.split(':').last }
  self.internal_links = links.filter do |link|
    link.href.include? ENV["PAGE_URL"]  
  end.collect { |link| link.href  }.uniq
  self.url = browser.url
  self.html = browser.html
  self.text = browser.text
  self.title = browser.title
  puts "Found #{links.count} links, #{emails.count} emails at #{url} (#{title})"
end

Instance Attribute Details

#emailsArray

Returns List of emails.

Returns:

  • (Array)

    List of emails



11
12
13
# File 'lib/generic_test/page.rb', line 11

def emails
  @emails
end

#htmlObject

Returns the value of attribute html.



13
14
15
# File 'lib/generic_test/page.rb', line 13

def html
  @html
end

Returns List of urls that include domain being tested.

Returns:

  • (Array)

    List of urls that include domain being tested



9
10
11
# File 'lib/generic_test/page.rb', line 9

def internal_links
  @internal_links
end

Returns List of links elements on the page.

Returns:

  • (Array)

    List of links elements on the page



7
8
9
# File 'lib/generic_test/page.rb', line 7

def links
  @links
end

#textObject

Returns the value of attribute text.



14
15
16
# File 'lib/generic_test/page.rb', line 14

def text
  @text
end

#titleObject

Returns the value of attribute title.



15
16
17
# File 'lib/generic_test/page.rb', line 15

def title
  @title
end

#urlObject

Returns the value of attribute url.



12
13
14
# File 'lib/generic_test/page.rb', line 12

def url
  @url
end