File tree 14 files changed +114
-95
lines changed
spec/datadog/ci/contrib/selenium
14 files changed +114
-95
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ TEST_METADATA = {
68
68
"knapsack_pro-7-rspec-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby"
69
69
} ,
70
70
"selenium" => {
71
- "selenium-4-capybara-3" => "❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby"
71
+ "selenium-4-capybara-3" => "❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby"
72
72
} ,
73
73
"timecop" => {
74
74
"timecop-0" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby"
Original file line number Diff line number Diff line change 2
2
3
3
require_relative "../patcher"
4
4
5
- require_relative "ext"
6
- require_relative "rum"
5
+ require_relative "../../ext/rum"
7
6
require_relative "../../ext/test"
7
+ require_relative "../../utils/rum"
8
8
9
9
module Datadog
10
10
module CI
@@ -22,10 +22,10 @@ def reset!
22
22
23
23
Datadog . logger . debug ( "[Selenium] Capybara session reset event" )
24
24
25
- RUM . stop_rum_session ( @browser )
25
+ Utils :: RUM . stop_rum_session ( @browser )
26
26
27
27
Datadog . logger . debug ( "[Selenium] RUM session stopped, deleting cookie" )
28
- @browser . manage . delete_cookie ( Ext ::COOKIE_TEST_EXECUTION_ID )
28
+ @browser . manage . delete_cookie ( CI :: Ext :: RUM ::COOKIE_TEST_EXECUTION_ID )
29
29
rescue ::Selenium ::WebDriver ::Error ::WebDriverError => e
30
30
Datadog . logger . debug ( "[Selenium] Error while resetting Capybara session: #{ e . message } " )
31
31
ensure
Original file line number Diff line number Diff line change 5
5
require_relative "../ext"
6
6
require_relative "../../settings"
7
7
8
+ require_relative "../../../ext/rum"
9
+
8
10
module Datadog
9
11
module CI
10
12
module Contrib
@@ -21,7 +23,7 @@ class Settings < Datadog::CI::Contrib::Settings
21
23
22
24
option :rum_flush_wait_millis do |o |
23
25
o . type :int
24
- o . env Ext ::ENV_RUM_FLUSH_WAIT_MILLIS
26
+ o . env CI :: Ext :: RUM ::ENV_RUM_FLUSH_WAIT_MILLIS
25
27
o . default 500
26
28
end
27
29
end
Original file line number Diff line number Diff line change 2
2
3
3
require_relative "../patcher"
4
4
5
- require_relative "ext "
6
- require_relative "rum"
5
+ require_relative "../../utils/rum "
6
+ require_relative "../../ext/ rum"
7
7
require_relative "../../ext/test"
8
8
9
9
module Datadog
@@ -22,10 +22,10 @@ def quit
22
22
23
23
Datadog . logger . debug ( "[Selenium] Driver quit event" )
24
24
25
- RUM . stop_rum_session ( @bridge )
25
+ Utils :: RUM . stop_rum_session ( @bridge )
26
26
27
27
Datadog . logger . debug ( "[Selenium] RUM session stopped, deleting cookie" )
28
- @bridge . manage . delete_cookie ( Ext ::COOKIE_TEST_EXECUTION_ID )
28
+ @bridge . manage . delete_cookie ( CI :: Ext :: RUM ::COOKIE_TEST_EXECUTION_ID )
29
29
rescue ::Selenium ::WebDriver ::Error ::WebDriverError => e
30
30
Datadog . logger . debug ( "[Selenium] Error while quitting Selenium driver: #{ e . message } " )
31
31
ensure
Original file line number Diff line number Diff line change @@ -8,21 +8,6 @@ module Selenium
8
8
# @public_api
9
9
module Ext
10
10
ENV_ENABLED = "DD_CIVISIBILITY_SELENIUM_ENABLED"
11
- ENV_RUM_FLUSH_WAIT_MILLIS = "DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS"
12
-
13
- COOKIE_TEST_EXECUTION_ID = "datadog-ci-visibility-test-execution-id"
14
-
15
- SCRIPT_IS_RUM_ACTIVE = <<~JS
16
- return !!window.DD_RUM
17
- JS
18
- SCRIPT_STOP_RUM_SESSION = <<~JS
19
- if (window.DD_RUM && window.DD_RUM.stopSession) {
20
- window.DD_RUM.stopSession();
21
- return true;
22
- } else {
23
- return false;
24
- }
25
- JS
26
11
end
27
12
end
28
13
end
Original file line number Diff line number Diff line change 2
2
3
3
require_relative "../patcher"
4
4
5
- require_relative "ext"
5
+ require_relative "../../ ext/rum "
6
6
require_relative "../../ext/test"
7
7
8
8
module Datadog
@@ -32,7 +32,7 @@ def to(url)
32
32
return result unless active_test
33
33
34
34
# Set the test's trace id as a cookie in browser session
35
- cookie_hash = { name : Ext ::COOKIE_TEST_EXECUTION_ID , value : active_test . trace_id . to_s }
35
+ cookie_hash = { name : CI :: Ext :: RUM ::COOKIE_TEST_EXECUTION_ID , value : active_test . trace_id . to_s }
36
36
Datadog . logger . debug { "[Selenium] Setting cookie: #{ cookie_hash } " }
37
37
@bridge . manage . add_cookie ( cookie_hash )
38
38
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module CI
5
+ module Ext
6
+ # Defines constants for Git tags
7
+ module RUM
8
+ ENV_RUM_FLUSH_WAIT_MILLIS = "DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS"
9
+
10
+ COOKIE_TEST_EXECUTION_ID = "datadog-ci-visibility-test-execution-id"
11
+
12
+ SCRIPT_IS_RUM_ACTIVE = <<~JS
13
+ return !!window.DD_RUM
14
+ JS
15
+ SCRIPT_STOP_RUM_SESSION = <<~JS
16
+ if (window.DD_RUM && window.DD_RUM.stopSession) {
17
+ window.DD_RUM.stopSession();
18
+ return true;
19
+ } else {
20
+ return false;
21
+ }
22
+ JS
23
+ end
24
+ end
25
+ end
26
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ext/rum"
4
+ require_relative "../ext/test"
5
+ require_relative "parsing"
6
+
7
+ module Datadog
8
+ module CI
9
+ module Utils
10
+ # Provides functionality to interact with Datadog Real User Monitoring product
11
+ # via executing JavaScript code in the browser.
12
+ #
13
+ # Relevant docs: https://docs.datadoghq.com/real_user_monitoring/browser/
14
+ module RUM
15
+ def self . is_rum_active? ( script_executor )
16
+ is_rum_active_script_result = script_executor . execute_script ( Ext ::RUM ::SCRIPT_IS_RUM_ACTIVE )
17
+
18
+ Datadog . logger . debug { "[Selenium] SCRIPT_IS_RUM_ACTIVE result is #{ is_rum_active_script_result . inspect } " }
19
+
20
+ Utils ::Parsing . convert_to_bool ( is_rum_active_script_result )
21
+ end
22
+
23
+ def self . stop_rum_session ( script_executor )
24
+ config = Datadog . configuration . ci [ :selenium ]
25
+ if is_rum_active? ( script_executor )
26
+ Datadog ::CI . active_test &.set_tag (
27
+ CI ::Ext ::Test ::TAG_IS_RUM_ACTIVE ,
28
+ "true"
29
+ )
30
+
31
+ result = script_executor . execute_script ( Ext ::RUM ::SCRIPT_STOP_RUM_SESSION )
32
+ Datadog . logger . debug { "[RUM] SCRIPT_STOP_RUM_SESSION result is #{ result . inspect } " }
33
+
34
+ # introduce a delay to allow the RUM session to be stopped
35
+ delay = config [ :rum_flush_wait_millis ] / 1000.0
36
+ Datadog . logger . debug { "[RUM] Waiting for #{ delay } seconds" }
37
+ sleep ( delay )
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
Original file line number Diff line number Diff line change @@ -4,14 +4,6 @@ module Datadog
4
4
module Selenium
5
5
module Ext
6
6
ENV_ENABLED: "DD_CIVISIBILITY_SELENIUM_ENABLED"
7
-
8
- ENV_RUM_FLUSH_WAIT_MILLIS: "DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS"
9
-
10
- COOKIE_TEST_EXECUTION_ID: "datadog-ci-visibility-test-execution-id"
11
-
12
- SCRIPT_IS_RUM_ACTIVE: String
13
-
14
- SCRIPT_STOP_RUM_SESSION: String
15
7
end
16
8
end
17
9
end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module CI
5
+ module Ext
6
+ module RUM
7
+ ENV_RUM_FLUSH_WAIT_MILLIS: "DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS"
8
+
9
+ COOKIE_TEST_EXECUTION_ID: "datadog-ci-visibility-test-execution-id"
10
+
11
+ SCRIPT_IS_RUM_ACTIVE: String
12
+ SCRIPT_STOP_RUM_SESSION: String
13
+ end
14
+ end
15
+ end
16
+ end
Original file line number Diff line number Diff line change
1
+ module Datadog
2
+ module CI
3
+ module Utils
4
+ module RUM
5
+ def self.is_rum_active? : (untyped script_executor) -> bool
6
+
7
+ def self.stop_rum_session : (untyped script_executor) -> void
8
+ end
9
+ end
10
+ end
11
+ end
Original file line number Diff line number Diff line change 78
78
expect ( visited_urls ) . to eq ( [ "http://www.example.com" , "about:blank" ] )
79
79
expect ( executed_scripts ) . to eq (
80
80
[
81
- Datadog ::CI ::Contrib :: Selenium :: Ext ::SCRIPT_IS_RUM_ACTIVE ,
82
- Datadog ::CI ::Contrib :: Selenium :: Ext ::SCRIPT_STOP_RUM_SESSION ,
81
+ Datadog ::CI ::Ext :: RUM ::SCRIPT_IS_RUM_ACTIVE ,
82
+ Datadog ::CI ::Ext :: RUM ::SCRIPT_STOP_RUM_SESSION ,
83
83
"window.sessionStorage.clear()" ,
84
84
"window.localStorage.clear()" ,
85
- Datadog ::CI ::Contrib :: Selenium :: Ext ::SCRIPT_IS_RUM_ACTIVE ,
86
- Datadog ::CI ::Contrib :: Selenium :: Ext ::SCRIPT_STOP_RUM_SESSION
85
+ Datadog ::CI ::Ext :: RUM ::SCRIPT_IS_RUM_ACTIVE ,
86
+ Datadog ::CI ::Ext :: RUM ::SCRIPT_STOP_RUM_SESSION
87
87
]
88
88
)
89
89
You can’t perform that action at this time.
0 commit comments