<commit_before>require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'

module Capypage
  class Element
    attr_accessor :selector, :prefix, :finder_options, :base_element

    delegate :click, :set, :text, :all, :find, :[], :native, :disabled?, :selected?, :has_text?, :has_no_text?, :checked?, :has_selector?,
             :to => :capybara_element

    def initialize(selector, prefix = nil, options = {}, &block)
      options.reverse_merge! :match => :smart
      @selector = selector
      @prefix = prefix
      @finder_options = options
      @base_element = options.delete(:base_element) || Capybara.current_session
      block.call(self) if block.present?
    end

    def element(name, selector, options = {})
      base = self
      define_singleton_method(name) { Element.new(selector, prefix, options.reverse_merge!(:match => :first, :base_element => base)) }
    end

    def elements(name, selector, options = {}, &block)
      base = self
      define_singleton_method(name) { Elements.new(selector, prefix, options.reverse_merge!(:base_element => base), &block) }
    end

    def visible?(options = {})
      options.reverse_merge! finder_options
      options.reverse_merge! :wait => 2
      return capybara_element(options).visible?
    rescue Capybara::ElementNotFound
      false
    end

    protected
    def capybara_element(options = {})
      base_element.find(element_selector, options.reverse_merge(finder_options))
    end

    def element_selector
      [prefix, selector].compact.join(" ")
    end
  end
end<commit_msg>Dynamically pickup methods from Capybara::Node::Element.instance_methods<commit_after>require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'

module Capypage
  class Element
    attr_accessor :selector, :prefix, :finder_options, :base_element

    def initialize(selector, prefix = nil, options = {}, &block)
      options.reverse_merge! :match => :smart
      @selector = selector
      @prefix = prefix
      @finder_options = options
      @base_element = options.delete(:base_element) || Capybara.current_session
      block.call(self) if block.present?
    end

    def element(name, selector, options = {})
      base = self
      define_singleton_method(name) { Element.new(selector, prefix, options.reverse_merge!(:match => :first, :base_element => base)) }
    end

    def elements(name, selector, options = {}, &block)
      base = self
      define_singleton_method(name) { Elements.new(selector, prefix, options.reverse_merge!(:base_element => base), &block) }
    end

    def visible?(options = {})
      options.reverse_merge! finder_options
      options.reverse_merge! :wait => 2
      return capybara_element(options).visible?
    rescue Capybara::ElementNotFound
      false
    end

    protected
    def capybara_element(options = {})
      base_element.find(element_selector, options.reverse_merge(finder_options))
    end

    def element_selector
      [prefix, selector].compact.join(" ")
    end

    def self.capybara_element_methods
      Capybara::Node::Element.instance_methods - Object.methods
    end

    delegate *capybara_element_methods,
             :to => :capybara_element
  end
end
{'fraction_non_alphanumeric': 0.11131554737810488, 'fraction_numerical': 0.0006133088009812941, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '478972', 'n_tokens_mistral': 962, 'n_tokens_neox': 950, 'n_words': 205}