<commit_before>module ActivePage
  class Page

    def self.validates_path(path)
      send :define_method, :path do
        path
      end

      send :define_method, :validate_path do
        session.current_path == self.path
      end
    end

    def self.validates_selector(selector)
      selector = selector.to_s
      send :define_method, "active_page_validate_#{ selector.gsub(/\W/, '_') }" do
        return has_css_selector?(selector), selector
      end
    end

    def self.submit_button_or_link_selector(selector)
      send :define_method, :submit_button_or_link_selector do
        selector
      end
    end

    attr_reader :path
    submit_button_or_link_selector '#submit'

    def initialize
      @session = Capybara.current_session
    end

    #=====================
    # ACTIONS
    #=====================

    def visit
      session.visit path
    end

    def fill_in(field_id, value)
      unless session.has_selector? "##{ field_id.to_s }"
        raise PageAssertionError, "#{ self.class }: Can't find any field with id='#{ field_id }'"
      end
      session.fill_in field_id.to_s, :with => value
    end

    def submit
      unless session.has_selector? "#{ submit_button_or_link_selector }"
        raise PageAssertionError, "#{ self.class }: Can't find a submit button with css selector '#{ submit_button_or_link_selector }'"
      end
      session.find("#{ submit_button_or_link_selector }").click
    end

    def find(selector)
      session.find("#{ selector }")
    end

    #=====================
    # QUERIES
    #=====================

    def is_current?
      session.current_path == self.path
    end

    def is_valid?
      is_current? && missing_selectors.length == 0<commit_msg>Add ability to find by xpath<commit_after>module ActivePage
  class Page

    def self.validates_path(path)
      send :define_method, :path do
        path
      end

      send :define_method, :validate_path do
        session.current_path == self.path
      end
    end

    def self.validates_selector(selector)
      selector = selector.to_s
      send :define_method, "active_page_validate_#{ selector.gsub(/\W/, '_') }" do
        return has_css_selector?(selector), selector
      end
    end

    def self.submit_button_or_link_selector(selector)
      send :define_method, :submit_button_or_link_selector do
        selector
      end
    end

    attr_reader :path
    submit_button_or_link_selector '#submit'

    def initialize
      @session = Capybara.current_session
    end

    #=====================
    # ACTIONS
    #=====================

    def visit
      session.visit path
    end

    def fill_in(field_id, value)
      unless session.has_selector? "##{ field_id.to_s }"
        raise PageAssertionError, "#{ self.class }: Can't find any field with id='#{ field_id }'"
      end
      session.fill_in field_id.to_s, :with => value
    end

    def submit
      unless session.has_selector? "#{ submit_button_or_link_selector }"
        raise PageAssertionError, "#{ self.class }: Can't find a submit button with css selector '#{ submit_button_or_link_selector }'"
      end
      session.find("#{ submit_button_or_link_selector }").click
    end

    def find(selector)
      session.find(selector)
    end

    def find_by_xpath(the_xpath)
      session.find(:xpath, the_xpath)
    end

    #=====================
    # QUERIES
    #=====================

    def is_current?
      session.current_path == self.path
    end

    def is_valid?
      is_current? && missing_selectors.length == 0
{'fraction_non_alphanumeric': 0.12992125984251968, 'fraction_numerical': 0.0005624296962879641, 'mean_word_length': 2.7560718057022173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2093971', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1054, 'n_words': 244}