Module: Datadog::CI::Contrib::Selenium::RUM

Defined in:
lib/datadog/ci/contrib/selenium/rum.rb

Overview

Provides functionality to interact with Datadog Real User Monitoring product via executing JavaScript code in the browser.

Relevant docs: docs.datadoghq.com/real_user_monitoring/browser/

Class Method Summary collapse

Class Method Details

.is_rum_active?(script_executor) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/datadog/ci/contrib/selenium/rum.rb', line 18

def self.is_rum_active?(script_executor)
  is_rum_active_script_result = script_executor.execute_script(Ext::SCRIPT_IS_RUM_ACTIVE)
  Datadog.logger.debug { "[Selenium] SCRIPT_IS_RUM_ACTIVE result is #{is_rum_active_script_result.inspect}" }
  Utils::Parsing.convert_to_bool(is_rum_active_script_result)
end

.stop_rum_session(script_executor) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/datadog/ci/contrib/selenium/rum.rb', line 24

def self.stop_rum_session(script_executor)
  config = Datadog.configuration.ci[:selenium]
  if is_rum_active?(script_executor)
    Datadog::CI.active_test&.set_tag(
      CI::Ext::Test::TAG_IS_RUM_ACTIVE,
      "true"
    )

    result = script_executor.execute_script(Ext::SCRIPT_STOP_RUM_SESSION)
    Datadog.logger.debug { "[Selenium] SCRIPT_STOP_RUM_SESSION result is #{result.inspect}" }

    # introduce a delay to allow the RUM session to be stopped
    delay = config[:rum_flush_wait_millis] / 1000.0
    Datadog.logger.debug { "[Selenium] Waiting for #{delay} seconds" }
    sleep(delay)
  end
end