Module: Capybara::Apparition::Browser::Window

Included in:
Capybara::Apparition::Browser
Defined in:
lib/capybara/apparition/browser/window.rb

Instance Method Summary collapse

Instance Method Details

#close_window(handle) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/capybara/apparition/browser/window.rb', line 42

def close_window(handle)
  @current_page_handle = nil if @current_page_handle == handle
  page = @pages.delete(handle)

  warn 'Window was already closed unexpectedly' unless page
  command('Target.closeTarget', targetId: handle)
end

#current_window_handleObject



6
7
8
# File 'lib/capybara/apparition/browser/window.rb', line 6

def current_window_handle
  @current_page_handle
end

#open_new_windowObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/capybara/apparition/browser/window.rb', line 27

def open_new_window
  context_id = current_page.browser_context_id
  target_id = command('Target.createTarget', url: 'about:blank', browserContextId: context_id)['targetId']
  session_id = command('Target.attachToTarget', targetId: target_id)['sessionId']
  session = Capybara::Apparition::DevToolsProtocol::Session.new(self, client, session_id)
  @pages.create(target_id, session, context_id,
                ignore_https_errors: ignore_https_errors,
                js_errors: js_errors,
                url_whitelist: @url_whitelist,
                extensions: @extensions,
                url_blacklist: @url_blacklist).inherit(current_page(allow_nil: true))
  @pages[target_id].send(:main_frame).loaded!
  target_id
end

#switch_to_window(handle) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capybara/apparition/browser/window.rb', line 14

def switch_to_window(handle)
  page = @pages[handle]
  unless page
    page = @pages[find_window_handle(handle)]
    warn 'Finding window by name, title, or url is deprecated, please use a block/proc ' \
         'with Session#within_window/Session#switch_to_window instead.'
  end
  raise NoSuchWindowError unless page

  page.wait_for_loaded
  @current_page_handle = page.target_id
end

#window_handlesObject



10
11
12
# File 'lib/capybara/apparition/browser/window.rb', line 10

def window_handles
  @pages.ids
end