<commit_before>
module Autobots
  module PageObjects
    module Overlay

      # A Overlay represents a portion (an element) of a page that is repeated
      # or reproduced multiple times, either on the same page, or across multiple
      # page objects or page modules.
      class Base
        include Utils::Castable
        include Utils::PageObjectHelper
        include Utils::OverlayAndWidgetHelper

        attr_reader :driver

        def initialize(page)
          @driver = page.driver
          @page = page

          # works here but not in initialize of base of page objects
          # because a page instance is already present when opening an overlay
          wait_for_ajax
          wait_for_dom
        end

        ## for overlay that include Utils::OverlayAndWidgetHelper
        def page_object
          @page
        end

        # By default, any driver state is accepted for any page. This method
        # should be overridden in subclasses.
        def validate!
          true
        end

        # Wait for all dom events to load
        def wait_for_dom(timeout = 15)
          uuid = SecureRandom.uuid
          # make sure body is loaded before appending anything to it
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for body to load").until do
            is_element_present?(:css, 'body')
          end
          driver.execute_script <<-EOS
            _.defer(function() {
            $('body').append("<div id='#{uuid}'></div>");
            });
          EOS
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all dom events to finish").until do
            is_element_present?(:css, "div[id='#{uuid}']")
          end
        end

        # Wait on all AJAX requests to finish
        def wait_for_ajax(timeout = 15)
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all ajax requests to finish").until do
            driver.execute_script('return jQuery.active == 0', driver)
          end
        end

        # Explicitly wait for a certain condition to be true:
        #   wait.until { driver.find_element(:css, 'body.tmpl-srp') }
        # when timeout is not specified, default timeout 5 sec will be used
        # when timeout is larger than 15, max timeout 15 sec will be used
        def wait(opts = {})
          if !opts[:timeout].nil? && opts[:timeout] > 15
            puts "WARNING: #{opts[:timeout]} sec timeout is NOT supported by wait method,
                max timeout 15 sec will be used instead"
            opts[:timeout] = 15
          end
          Selenium::WebDriver::Wait.new(opts)
        end

      end

    end
  end
end

<commit_msg>minor fix for wait_for_ajax in overlay/base.rb<commit_after>
module Autobots
  module PageObjects
    module Overlay

      # A Overlay represents a portion (an element) of a page that is repeated
      # or reproduced multiple times, either on the same page, or across multiple
      # page objects or page modules.
      class Base
        include Utils::Castable
        include Utils::PageObjectHelper
        include Utils::OverlayAndWidgetHelper

        attr_reader :driver

        def initialize(page)
          @driver = page.driver
          @page = page

          # works here but not in initialize of base of page objects
          # because a page instance is already present when opening an overlay
          wait_for_ajax
          wait_for_dom
        end

        ## for overlay that include Utils::OverlayAndWidgetHelper
        def page_object
          @page
        end

        # By default, any driver state is accepted for any page. This method
        # should be overridden in subclasses.
        def validate!
          true
        end

        # Wait for all dom events to load
        def wait_for_dom(timeout = 15)
          uuid = SecureRandom.uuid
          # make sure body is loaded before appending anything to it
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for body to load").until do
            is_element_present?(:css, 'body')
          end
          driver.execute_script <<-EOS
            _.defer(function() {
            $('body').append("<div id='#{uuid}'></div>");
            });
          EOS
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all dom events to finish").until do
            is_element_present?(:css, "div[id='#{uuid}']")
          end
        end

        # Wait on all AJAX requests to finish
        def wait_for_ajax(timeout = 15)
          wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all ajax requests to finish").until do
            driver.execute_script 'return window.jQuery != undefined && jQuery.active == 0'
          end
        end

        # Explicitly wait for a certain condition to be true:
        #   wait.until { driver.find_element(:css, 'body.tmpl-srp') }
        # when timeout is not specified, default timeout 5 sec will be used
        # when timeout is larger than 15, max timeout 15 sec will be used
        def wait(opts = {})
          if !opts[:timeout].nil? && opts[:timeout] > 15
            puts "WARNING: #{opts[:timeout]} sec timeout is NOT supported by wait method,
                max timeout 15 sec will be used instead"
            opts[:timeout] = 15
          end
          Selenium::WebDriver::Wait.new(opts)
        end

      end

    end
  end
end


{'fraction_non_alphanumeric': 0.07595870206489676, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 1.995582551076753, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1356384', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1360, 'n_words': 547}