<commit_before>module Gridium
  class Page

    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)
      if asserted_element.eql? nil
        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={})
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:css, css).enabled?}
      rescue Exception => e
        return false
      end
    end

    def self.has_xpath?(xpath, options={})
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:xpath, xpath).enabled?}
      rescue Exception => e
        return false
      end
    end

    def self.has_link?(linktext)
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:link_text, linktext).enabled?}
      rescue Exception => e
        return false
      end
    end

    def self.has_text?(text)
      has_flash?(text)
    end

    def self.has_flash?(text)
      wait = Selenium::WebDriver::Wait.new(:timeout => 5) #5 seconds every 500ms
      begin
        element = wait.until {Driver.html.include? text}
      rescue
        Log.warn("Could not find the flash message!")
      end

      if element
        return true
      else
        return false
      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(link_text)
      Element.new("Clicking #{link_text} Link", :link_text, link_text).click
    end

    def click_button(button_name)
      #The button maybe a link that looks like a button - we want to handle both
      button = Element.new("A #{button_name} button", :xpath, "//button[contains(., '#{button_name}')]")
      begin
        button.click
      rescue Exception => e
        Log.debug("Button not found - Attempting Link - speed up test by using click_link method if this works...")
        link = Element.new("A #{button_name} link", :xpath, "//a[contains(., '#{button_name}')]")
        link.click
      end
    end

    def check(id) #checks a checkbox
      Driver.driver.find_element(:id, id).click
    end
  end
end<commit_msg>linting<commit_after>module Gridium
  class Page

    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)
      if asserted_element.eql? nil
        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={})
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:css, css).enabled?}
      rescue Exception
        return false
      end
    end

    def self.has_xpath?(xpath, options={})
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:xpath, xpath).enabled?}
      rescue Exception
        return false
      end
    end

    def self.has_link?(linktext)
      wait = Selenium::WebDriver::Wait.new(:timeout => 5)
      begin
        wait.until {Driver.driver.find_element(:link_text, linktext).enabled?}
      rescue Exception
        return false
      end
    end

    def self.has_text?(text)
      has_flash?(text)
    end

    def self.has_flash?(text)
      wait = Selenium::WebDriver::Wait.new(:timeout => 5) #5 seconds every 500ms
      begin
        element = wait.until {Driver.html.include? text}
      rescue
        Log.warn("Could not find the flash message!")
      end

      if element
        return true
      else
        return false
      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(link_text)
      Element.new("Clicking #{link_text} Link", :link_text, link_text).click
    end

    def click_button(button_name)
      #The button maybe a link that looks like a button - we want to handle both
      button = Element.new("A #{button_name} button", :xpath, "//button[contains(., '#{button_name}')]")
      begin
        button.click
      rescue Exception
        Log.debug("Button not found - Attempting Link - speed up test by using click_link method if this works...")
        link = Element.new("A #{button_name} link", :xpath, "//a[contains(., '#{button_name}')]")
        link.click
      end
    end

    def check(id) #checks a checkbox
      Driver.driver.find_element(:id, id).click
    end
  end
end
{'fraction_non_alphanumeric': 0.1067193675889328, 'fraction_numerical': 0.007246376811594203, 'mean_word_length': 2.566059894304169, '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': '6556513', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1857, 'n_words': 471}