Class: Watir::Window

Inherits:
Object show all
Defined in:
lib/watir-webdriver/window_switching.rb

Overview

WindowSwitching

Instance Method Summary collapse

Constructor Details

#initialize(driver, id) ⇒ Window

Returns a new instance of Window.



47
48
49
# File 'lib/watir-webdriver/window_switching.rb', line 47

def initialize(driver, id)
  @driver, @id = driver, id
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



55
56
57
58
59
# File 'lib/watir-webdriver/window_switching.rb', line 55

def ==(other)
  return false unless other.kind_of?(self.class)

  @id == other.id
end

#closeObject



70
71
72
# File 'lib/watir-webdriver/window_switching.rb', line 70

def close
  use { @driver.close }
end

#current?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/watir-webdriver/window_switching.rb', line 66

def current?
  @driver.window_handle == @id
end

#hashObject



62
63
64
# File 'lib/watir-webdriver/window_switching.rb', line 62

def hash
  @id.hash ^ self.class.hash
end

#inspectObject



51
52
53
# File 'lib/watir-webdriver/window_switching.rb', line 51

def inspect
  '#<%s:0x%x id=%s>' % [self.class, hash*2, @id.to_s]
end

#titleObject



74
75
76
77
78
79
# File 'lib/watir-webdriver/window_switching.rb', line 74

def title
  title = nil
  use { title = @driver.title }

  title
end

#urlObject



81
82
83
84
85
86
# File 'lib/watir-webdriver/window_switching.rb', line 81

def url
  url = nil
  use { url = @driver.current_url }

  url
end

#use(&blk) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/watir-webdriver/window_switching.rb', line 88

def use(&blk)
  if current?
    yield if block_given?
    return self
  end

  @driver.switch_to.window(@id, &blk)
  self
end