<commit_before>ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
require 'capybara/minitest'
require 'database_cleaner'

class ActiveSupport::TestCase
  include FactoryBot::Syntax::Methods

  def assert_invalid(instance, property)
    assert instance.invalid?
    assert instance.errors.messages[property].any?
  end
end

class ActionDispatch::IntegrationTest
  # For all integration tests with FactoryBot + Capybara + JS driver
  self.use_transactional_tests = false

  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL
  # Make `assert_*` methods behave like Minitest assertions
  include Capybara::Minitest::Assertions

  # Use chrome driver for Capybara
  Capybara.default_driver = :selenium
  Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(app, browser: :chrome)
  end

  DatabaseCleaner.strategy = :truncation

  def setup
    # Database cleaner
    DatabaseCleaner.start
  end

  def teardown
    # Reset sessions and driver between tests
    visit root_path
    Capybara.reset_sessions!
    Capybara.use_default_driver
    DatabaseCleaner.clean
  end

  def assert_invalid(instance, property)
    assert instance.invalid?
    assert instance.errors.messages[property].any?
  end

  def click_main_nav_item(nav_id, link_text, assertion_selector)<commit_msg>:sparkles: Add headless-browser test code<commit_after>ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
require 'capybara/minitest'
require 'database_cleaner'

class ActiveSupport::TestCase
  include FactoryBot::Syntax::Methods

  def assert_invalid(instance, property)
    assert instance.invalid?
    assert instance.errors.messages[property].any?
  end
end

class ActionDispatch::IntegrationTest
  # For all integration tests with FactoryBot + Capybara + JS driver
  self.use_transactional_tests = false

  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL
  # Make `assert_*` methods behave like Minitest assertions
  include Capybara::Minitest::Assertions

  # Use chrome driver for Capybara
  # To force-upgrade to the latest version of chromedriver:
  #   delete the directory $HOME/.chromedriver-helper
  #   run chromedriver-update
  Capybara.default_driver = :selenium
  Capybara.register_driver :selenium do |app|
    # Capybara::Selenium::Driver.new(app, browser: :chrome)
    # For headless chrome browser
    Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options: { args: %w[headless disable-gpu window-size=1680,1050] }))
  end

  DatabaseCleaner.strategy = :truncation

  def setup
    # Database cleaner
    DatabaseCleaner.start
  end

  def teardown
    # Reset sessions and driver between tests
    visit root_path
    Capybara.reset_sessions!
    Capybara.use_default_driver
    DatabaseCleaner.clean
  end

  def assert_invalid(instance, property)
    assert instance.invalid?
    assert instance.errors.messages[property].any?
  end

  def click_main_nav_item(nav_id, link_text, assertion_selector)
{'fraction_non_alphanumeric': 0.08338461538461539, 'fraction_numerical': 0.0024615384615384616, 'mean_word_length': 4.795008912655971, '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': '7419467', 'n_tokens_mistral': 1007, 'n_tokens_neox': 960, 'n_words': 246}