<commit_before>module Gridium
  class Page

    def initialize

    end

    def self.switch_to_frame(frame)
      Driver.driver.switch_to.frame(frame)
    end

    def self.switch_to_default
      Driver.driver.switch_to.default_content
    end

    def self.assert_selector(by, locator)
      asserted_element = Element.new("Asserted Element", by, locator)
      unless asserted_element.enabled?
        fail("Could not find element on page with locator #{locator} using #{by}")
      else
        Log.info("Asserted Element present with locator #{locator} using #{by}")
      end
    end

    def self.has_css?(css, options={})
      begin
        Driver.driver.find_element(:css, css).enabled?
      rescue Exception => e
        return false
      end
    end

    def self.has_xpath?(xpath, options={})
      begin
        Driver.driver.find_element(:xpath, xpath).enabled?
      rescue Exception => e
        return false
      end

    end

    def self.has_link?(linktext)
      begin
        Driver.driver.find_element(:link_text, linktext).enabled?
      rescue Exception => e
        return false
      end
    end

    def self.has_text?(text)
      unless Driver.html.include? text
        Log.warn("Could not find expected text: #{text} on page.")
        return false
      else
        return true
      end
    end

    def self.scroll_to_bottom
      Driver.execute_script('window.scrollTo(0,100000)')
    end

    def self.scroll_to_top
      #TODO Verify this
      Driver.execute_script('window.scrollTo(100000,0)')
    end

    def self.execute_script(script)
      Driver.execute_script(script)
    end

    def all(by, locator)
      Driver.driver.find_elements(by, locator)
    end

    def find(by, locator)
      Element.new("Page Find Element", by, locator)
    end

    def first(by, locator)
      Driver.driver.find_elements(by, locator).first
    end

    def click_link(linktext)
      link = Driver.driver.find_element(:link, linktext)
      link.click
    end

    def click_button(button_name)
      #The button maybe a link that looks like a button - we want to handle both<commit_msg>Updated how Page executes scripts<commit_after>module Gridium
  class Page

    def initialize

    end

    def self.switch_to_frame(frame)
      Driver.driver.switch_to.frame(frame)
    end

    def self.switch_to_default
      Driver.driver.switch_to.default_content
    end

    def self.assert_selector(by, locator)
      asserted_element = Element.new("Asserted Element", by, locator)
      unless asserted_element.enabled?
        fail("Could not find element on page with locator #{locator} using #{by}")
      else
        Log.info("Asserted Element present with locator #{locator} using #{by}")
      end
    end

    def self.has_css?(css, options={})
      begin
        Driver.driver.find_element(:css, css).enabled?
      rescue Exception => e
        return false
      end
    end

    def self.has_xpath?(xpath, options={})
      begin
        Driver.driver.find_element(:xpath, xpath).enabled?
      rescue Exception => e
        return false
      end

    end

    def self.has_link?(linktext)
      begin
        Driver.driver.find_element(:link_text, linktext).enabled?
      rescue Exception => e
        return false
      end
    end

    def self.has_text?(text)
      unless Driver.html.include? text
        Log.warn("Could not find expected text: #{text} on page.")
        return false
      else
        return true
      end
    end

    def self.scroll_to_bottom
      Driver.execute_script_driver('window.scrollTo(0,100000)')
    end

    def self.scroll_to_top
      #TODO Verify this
      Driver.execute_script_driver('window.scrollTo(100000,0)')
    end

    def self.execute_script(script)
      Driver.execute_script_driver(script)
    end

    def all(by, locator)
      Driver.driver.find_elements(by, locator)
    end

    def find(by, locator)
      Element.new("Page Find Element", by, locator)
    end

    def first(by, locator)
      Driver.driver.find_elements(by, locator).first
    end

    def click_link(linktext)
      link = Driver.driver.find_element(:link, linktext)
      link.click
    end

    def click_button(button_name)
      #The button maybe a link that looks like a button - we want to handle both
{'fraction_non_alphanumeric': 0.08630744110100304, 'fraction_numerical': 0.006531373921156987, 'mean_word_length': 2.460855528652139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5027392', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1276, 'n_words': 333}