Sha256: b59fc2aae3ff16f90b679a7bb14ed27add88427f2f9ded77ef4b8c04ed0e94b0

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Bga
    class Session < ::SimpleDelegator
      module SkipTrophies
        TROPHY_SKIP_BUTTON_XPATH = '//*[@id = "splashedNotifications_overlay"]' \
          '//*[starts-with(@id, "continue_btn_")]'
        TROPHY_SKIP_TIMEOUT = 5

        # @param &block [Proc]
        # @return [Selenium::WebDriver::Error::TimeoutError, nil]
        def on_rescue_timeout(&block)
          block.call
          nil
        rescue ::Selenium::WebDriver::Error::TimeoutError => e
          e
        end

        def on_skip_trophies(&block)
          error = on_rescue_timeout(&block)
          return unless error
          raise error unless skip_trophy_overlay?

          skip_trophies
        end

        def skip_trophies
          loop do
            wait_for_click({ xpath: TROPHY_SKIP_BUTTON_XPATH }, TROPHY_SKIP_TIMEOUT)
          rescue ::Selenium::WebDriver::Error::TimeoutError
            break
          end
        end

        # @return [Boolean]
        def skip_trophy_overlay?
          find_element(xpath: TROPHY_SKIP_BUTTON_XPATH).present?
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.26.0 lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb
ehbrs_ruby_utils-0.25.1 lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb