Module: CapybaraInlineScreenshot

Defined in:
lib/capybara-inline-screenshot.rb

Defined Under Namespace

Modules: Minitest, Rspec

Class Method Summary collapse

Class Method Details

.artifact_escape_code_for_image(path) ⇒ Object



24
25
26
27
# File 'lib/capybara-inline-screenshot.rb', line 24

def self.artifact_escape_code_for_image(path)
  relative_path = path.sub(/\A#{base_artifact_dir}\/?/, '')
  "\e]1338;url=artifact://#{relative_path}\a"
end

.base64_escape_code_for_image(path) ⇒ Object



29
30
31
32
33
# File 'lib/capybara-inline-screenshot.rb', line 29

def self.base64_escape_code_for_image(path)
  name = inline_base64(File.basename(path))
  image = inline_base64(File.read(path))
  "\e]1337;File=name=#{name};inline=1:#{image}\a"
end

.base_artifact_dirObject



12
13
14
# File 'lib/capybara-inline-screenshot.rb', line 12

def self.base_artifact_dir
  @base_artifact_dir || (Rails.root if defined? Rails)
end

.base_artifact_dir=(path) ⇒ Object

Sets the default base directory for artifacts (usually the root dir of the project). Defaults to Rails.root but can be set to another value if you’re not using Rails.



8
9
10
# File 'lib/capybara-inline-screenshot.rb', line 8

def self.base_artifact_dir=(path)
  @base_artifact_dir = path
end

.escape_code_for_image(path) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/capybara-inline-screenshot.rb', line 16

def self.escape_code_for_image(path)
  if ENV['CI'] || ENV['CAPYBARA_INLINE_SCREENSHOT'] == 'artifact'
    artifact_escape_code_for_image(path)
  else
    base64_escape_code_for_image(path)
  end
end

.inline_base64(string) ⇒ Object



35
36
37
# File 'lib/capybara-inline-screenshot.rb', line 35

def self.inline_base64(string)
  Base64.encode64(string).gsub("\n",'')
end