Class: Seleniumrc::SeleniumPage

Inherits:
Object
  • Object
show all
Includes:
WaitFor
Defined in:
lib/seleniumrc/selenium_page.rb

Constant Summary collapse

PAGE_LOADED_COMMAND =
"this.browserbot.getDocument().body ? true : false"

Instance Attribute Summary collapse

Attributes included from WaitFor

#default_timeout

Instance Method Summary collapse

Methods included from WaitFor

#default_wait_for_time, #flunk, #time_class, #wait_for

Constructor Details

#initialize(driver) ⇒ SeleniumPage

Returns a new instance of SeleniumPage.



7
8
9
# File 'lib/seleniumrc/selenium_page.rb', line 7

def initialize(driver)
  @driver = driver
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



4
5
6
# File 'lib/seleniumrc/selenium_page.rb', line 4

def driver
  @driver
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
74
# File 'lib/seleniumrc/selenium_page.rb', line 71

def ==(other)
  return false unless other.is_a?(SeleniumPage)
  self.driver == other.driver
end

#has_title(expected_title, params = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/seleniumrc/selenium_page.rb', line 16

def has_title(expected_title, params = {})
  wait_for(params) do |configuration|
    actual_title = driver.get_title
    configuration.message = "Expected title '#{expected_title}' but was '#{actual_title}'"
    has_title? expected_title, actual_title
  end
end

#has_title?(expected_title, actual_title = driver.get_title) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/seleniumrc/selenium_page.rb', line 23

def has_title?(expected_title, actual_title=driver.get_title)
  expected_title == actual_title
end

#is_text_not_present(unexpected_text, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/seleniumrc/selenium_page.rb', line 39

def is_text_not_present(unexpected_text, options = {})
  options = {
    :message => "Expected '#{unexpected_text}' to be absent, but it wasn't"
  }.merge(options)
  wait_for(options) do
    is_text_not_present? unexpected_text
  end
end

#is_text_not_present?(unexpected_text) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/seleniumrc/selenium_page.rb', line 47

def is_text_not_present?(unexpected_text)
  page_loaded? && !driver.is_text_present(unexpected_text)
end

#is_text_present(expected_text, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/seleniumrc/selenium_page.rb', line 27

def is_text_present(expected_text, options = {})
  options = {
    :message => "Expected '#{expected_text}' to be present, but it wasn't"
  }.merge(options)
  wait_for(options) do
    is_text_present? expected_text
  end
end

#is_text_present?(expected_text) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/seleniumrc/selenium_page.rb', line 35

def is_text_present?(expected_text)
  page_loaded? && driver.is_text_present(expected_text)
end

#open(url) ⇒ Object Also known as: open_and_wait



11
12
13
# File 'lib/seleniumrc/selenium_page.rb', line 11

def open(url)
  driver.open(url)
end

#page_loaded?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/seleniumrc/selenium_page.rb', line 51

def page_loaded?
  driver.get_eval(PAGE_LOADED_COMMAND) == true.to_s
end

#url_ends_with(ends_with, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/seleniumrc/selenium_page.rb', line 55

def url_ends_with(ends_with, options={})
  options = {
    :message => "Expected '#{driver.get_location}' to end with '#{ends_with}'"
  }.merge(options)
  wait_for(options) do
    url_ends_with? ends_with
  end
end

#url_ends_with?(ends_with) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/seleniumrc/selenium_page.rb', line 63

def url_ends_with?(ends_with)
  if driver.get_location =~ Regexp.new("#{Regexp.escape(ends_with)}$")
    true
  else
    false
  end
end