-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close RUM session on Capybara.reset_session! or WebDriver::Driver.qui…
…t; add finishing touches for the integration
- Loading branch information
1 parent
767b394
commit 691bf86
Showing
14 changed files
with
236 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ target :lib do | |
library "knapsack_pro" | ||
library "bundler" | ||
library "selenium-webdriver" | ||
library "capybara" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/tracing/contrib/patcher" | ||
|
||
require_relative "ext" | ||
require_relative "rum" | ||
require_relative "../../ext/test" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
# instruments Capybara::Selenium::Driver | ||
module CapybaraDriver | ||
def self.included(base) | ||
base.prepend(InstanceMethods) | ||
end | ||
|
||
module InstanceMethods | ||
def reset! | ||
return super unless datadog_configuration[:enabled] | ||
|
||
Datadog.logger.debug("[Selenium] Capybara session reset event") | ||
|
||
RUM.stop_rum_session(@browser) | ||
|
||
Datadog.logger.debug("[Selenium] RUM session stopped, deleting cookie") | ||
@browser.manage.delete_cookie(Ext::COOKIE_TEST_EXECUTION_ID) | ||
rescue ::Selenium::WebDriver::Error::WebDriverError => e | ||
Datadog.logger.debug("[Selenium] Error while resetting Capybara session: #{e.message}") | ||
ensure | ||
super | ||
end | ||
|
||
private | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:selenium] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/tracing/contrib/patcher" | ||
|
||
require_relative "ext" | ||
require_relative "rum" | ||
require_relative "../../ext/test" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
# instruments Selenium::WebDriver::Driver | ||
module Driver | ||
def self.included(base) | ||
base.prepend(InstanceMethods) | ||
end | ||
|
||
module InstanceMethods | ||
def quit | ||
return super unless datadog_configuration[:enabled] | ||
|
||
Datadog.logger.debug("[Selenium] Driver quit event") | ||
|
||
RUM.stop_rum_session(@bridge) | ||
|
||
Datadog.logger.debug("[Selenium] RUM session stopped, deleting cookie") | ||
@bridge.manage.delete_cookie(Ext::COOKIE_TEST_EXECUTION_ID) | ||
rescue ::Selenium::WebDriver::Error::WebDriverError => e | ||
Datadog.logger.debug("[Selenium] Error while quitting Selenium driver: #{e.message}") | ||
ensure | ||
super | ||
end | ||
|
||
private | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:selenium] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/tracing/contrib/patcher" | ||
|
||
require_relative "ext" | ||
require_relative "../../ext/test" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
# Provides functionality to interact with Datadog Real User Monitoring product | ||
# via executing JavaScript code in the browser. | ||
# | ||
# Relevant docs: https://docs.datadoghq.com/real_user_monitoring/browser/ | ||
module RUM | ||
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}" } | ||
is_rum_active_script_result == "true" || is_rum_active_script_result == true | ||
end | ||
|
||
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 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
module CapybaraDriver | ||
def self.included: (untyped base) -> untyped | ||
|
||
module InstanceMethods : Capybara::Selenium::Driver | ||
def reset!: () -> void | ||
|
||
private | ||
|
||
def datadog_configuration: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
module Driver | ||
def self.included: (untyped base) -> untyped | ||
|
||
module InstanceMethods : Selenium::WebDriver::Driver | ||
def quit: () -> void | ||
|
||
private | ||
|
||
def datadog_configuration: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Selenium | ||
module RUM | ||
def self.is_rum_active?: (untyped script_executor) -> bool | ||
|
||
def self.stop_rum_session: (untyped script_executor) -> void | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Capybara | ||
end | ||
|
||
module Capybara::Selenium | ||
end | ||
|
||
module Capybara::Selenium::Driver | ||
def reset!: () -> void | ||
end |