<commit_before>module Capybara
  module Screenshot
    class Saver
      attr_reader :capybara, :page, :file_base_name

      def initialize(capybara, page, html_save=true)
        @capybara, @page, @html_save = capybara, page, html_save
        @file_base_name = "screenshot-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
      end

      def save
        # if current_path empty then nothing to screen shot as browser has not loaded any URL
        return if capybara.current_path.to_s.empty?

        save_html if @html_save
        save_screenshot
      end

      def save_html
        require 'capybara/util/save_and_open_page'
        capybara.save_page(page.body, "#{file_base_name}.html")
      end

      def save_screenshot
        if Capybara::Screenshot.registered_drivers.has_key?(capybara.current_driver)
          Capybara::Screenshot.registered_drivers[capybara.current_driver].call(page.driver, screenshot_path)
        else
          warn "capybara-screenshot could not detect a screenshot driver for '#{capybara.current_driver}'. Saving with default with unknown results."
          save_with_default
        end
      end

      def save_with_default
        page.driver.render(screenshot_path)
      end

      def html_path
        "#{capybara.save_and_open_page_path}#{file_base_name}.html"
      end

      def screenshot_path
        File.join(Capybara::Screenshot.capybara_root, "#{file_base_name}.png")
      end

    end
  end
end
<commit_msg>Saver html_path should just use the capybara_root method<commit_after>module Capybara
  module Screenshot
    class Saver
      attr_reader :capybara, :page, :file_base_name

      def initialize(capybara, page, html_save=true)
        @capybara, @page, @html_save = capybara, page, html_save
        @file_base_name = "screenshot-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
      end

      def save
        # if current_path empty then nothing to screen shot as browser has not loaded any URL
        return if capybara.current_path.to_s.empty?

        save_html if @html_save
        save_screenshot
      end

      def save_html
        require 'capybara/util/save_and_open_page'
        capybara.save_page(page.body, "#{file_base_name}.html")
      end

      def save_screenshot
        if Capybara::Screenshot.registered_drivers.has_key?(capybara.current_driver)
          Capybara::Screenshot.registered_drivers[capybara.current_driver].call(page.driver, screenshot_path)
        else
          warn "capybara-screenshot could not detect a screenshot driver for '#{capybara.current_driver}'. Saving with default with unknown results."
          save_with_default
        end
      end

      def save_with_default
        page.driver.render(screenshot_path)
      end

      def html_path
        File.join(Capybara::Screenshot.capybara_root, "#{file_base_name}.html")
      end

      def screenshot_path
        File.join(Capybara::Screenshot.capybara_root, "#{file_base_name}.png")
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.08391842193246406, 'fraction_numerical': 0.0, 'mean_word_length': 2.816326530612245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7198919', 'n_tokens_mistral': 991, 'n_tokens_neox': 957, 'n_words': 202}