Class: Selenium::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/link.rb

Overview

Link class that models the behavior of a link

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser, locator, target = nil) ⇒ Link

Returns a new instance of Link.



15
16
17
18
19
# File 'lib/selenium/link.rb', line 15

def initialize(browser, locator, target = nil)
  @browser = browser
  @locator = locator
  @target = target
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



5
6
7
# File 'lib/selenium/link.rb', line 5

def browser
  @browser
end

Class Method Details

.by_id(browser, id, target = nil) ⇒ Object



7
8
9
# File 'lib/selenium/link.rb', line 7

def Link::by_id(browser, id, target = nil)
  Link.new(browser, "id=#{id}", target)
end

.by_text(browser, text, target = nil) ⇒ Object



11
12
13
# File 'lib/selenium/link.rb', line 11

def Link::by_text(browser, text, target = nil)
  Link.new(browser, "link=#{text}", target)
end

Instance Method Details

#clickObject

click the link



22
23
24
# File 'lib/selenium/link.rb', line 22

def click
  @browser.click(@locator)
end

#click_waitObject

click the link and wait for page to load



27
28
29
30
# File 'lib/selenium/link.rb', line 27

def click_wait
  click
  @browser.wait_for_page_to_load
end

#goObject

click the link, wait for the page to load, and asserts the target that was passed in during initialization



34
35
36
37
38
39
# File 'lib/selenium/link.rb', line 34

def go
  raise "target page not defined for link #{@locator}" unless @target
  click_wait
  @target.assert_on_page
  @target
end