module Capybara::WSL

Constants

VERSION

Public Class Methods

save_and_open_page(path = nil) click to toggle source
# File lib/capybara/wsl.rb, line 13
def self.save_and_open_page(path = nil)
  Capybara.current_session.save_page(path).tap do |s_path|
    open_file(s_path)
  end
end
save_and_open_screenshot(path = nil, **options) click to toggle source
# File lib/capybara/wsl.rb, line 19
def self.save_and_open_screenshot(path = nil, **options)
  Capybara.current_session.save_screenshot(path, options).tap do |s_path|
    open_file(s_path)
  end
end

Private Class Methods

detect_path() click to toggle source
# File lib/capybara/wsl.rb, line 39
def self.detect_path
  path = `wslpath -m "/"`&.strip

  if path.empty?
    raise(Capybara::WSL::CannotDetectWSLPath,
      "Cannot detect WSL path. Are you sure you're running WSL?")
  end

  "file:#{path}"
end
modify_path(path) click to toggle source
# File lib/capybara/wsl.rb, line 35
def self.modify_path(path)
  path[1..-1].prepend(detect_path).gsub("/", "\\")
end
open_file(path) click to toggle source
# File lib/capybara/wsl.rb, line 27
def self.open_file(path)
  Dotenv.overload!(File.expand_path("#{__FILE__}/../.env"))
  wsl_path = modify_path(path)
  Launchy.open(wsl_path)
rescue LoadError
  warn "File saved to #{wsl_path}.\nPlease install the launchy gem to open the file automatically."
end