@@ -60,58 +60,75 @@ public BrowserTCIFactory(final MutableCapabilities capabilities)
6060 this (capabilities , TCIServiceLoaderHolder .instance ().service (BrowserTCIFactoryConfig .class ));
6161 }
6262
63- @ SuppressWarnings ({"resource" , "checkstyle:MagicNumber" })
6463 public BrowserTCIFactory (final MutableCapabilities capabilities , final BrowserTCIFactoryConfig config )
6564 {
66- super (
67- (c , na ) -> new BrowserTCI (c , na , capabilities )
68- .withBidiEnabled (config .bidiEnabled ())
69- .withDeactivateCDPIfPossible (config .deactivateCdpIfPossible ())
70- .withClientConfig (ClientConfig .defaultConfig ()
71- .readTimeout (Duration .ofSeconds (60 + cpuSlownessFactor () * 10L )))
72- .withWebDriverRetryCount (Math .max (Math .min (cpuSlownessFactor (), 5 ), 1 ))
73- .withWebDriverRetrySec (25 + cpuSlownessFactor () * 5 )
74- .withBrowserConsoleLog (
75- logBrowserConsoleConsumer (config .browserConsoleLogLevel ()),
76- config .browserConsoleLogLevel ().logLevels ()),
77- () -> new SeleniumBrowserWebDriverContainer (capabilities )
78- .withStartRecordingContainerManually (true )
79- .withRecordingDirectory (config .dirForRecords ())
80- .withRecordingMode (config .recordingMode ())
81- // 2024-04 VNC is no longer required when recording
82- .withDisableVNC (!config .vncEnabled ())
83- .withEnableNoVNC (config .vncEnabled ())
84- .withRecordingContainerSupplier (t -> new SeleniumRecordingContainer (t )
85- .withFrameRate (10 )
86- .withLogConsumer (getLogConsumer ("container.browserrecorder." + capabilities .getBrowserName ()))
87- .withCreateContainerCmdModifier (cmd -> cmd .getHostConfig ().withMemory (ContainerMemory .M512M )))
88- // Without that a mount volume dialog shows up
89- // https://github.com/testcontainers/testcontainers-java/issues/1670
90- .withSharedMemorySize (ContainerMemory .M2G )
91- .withCreateContainerCmdModifier (cmd -> cmd .getHostConfig ().withMemory (ContainerMemory .M1G ))
92- .withEnv ("SE_SCREEN_WIDTH" , "1600" )
93- .withEnv ("SE_SCREEN_HEIGHT" , "900" )
94- // By default after 5 mins the session is killed and you can't use the container anymore. Cool or?
95- // https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#grid-url-and-session-timeout
96- .withEnv ("SE_NODE_SESSION_TIMEOUT" , "3600" )
97- // Disable local tracing, as we don't need it
98- // https://github.com/SeleniumHQ/docker-selenium/issues/2355
99- .withEnv ("SE_ENABLE_TRACING" , "false" )
100- // Some (AWS) CPUs are completely overloaded with the default 15s timeout -> increase it
101- .waitingFor (new WaitAllStrategy ()
102- .withStrategy (new LogMessageWaitStrategy ()
103- .withRegEx (".*(Started Selenium Standalone).*\n " )
104- .withStartupTimeout (Duration .ofSeconds (30 + 20L * cpuSlownessFactor ())))
105- .withStrategy (new HostPortWaitStrategy ())
106- .withStartupTimeout (Duration .ofSeconds (30 + 20L * cpuSlownessFactor ()))),
65+ this (
66+ (c , na ) -> createDefaultBrowserTCI (c , na , capabilities , config ),
67+ () -> createDefaultContainer (capabilities , config ),
10768 "selenium-" + capabilities .getBrowserName ().toLowerCase (),
10869 "container.browserwebdriver." + capabilities .getBrowserName (),
109- "Browser-" + capabilities .getBrowserName ());
110- this . browserName = capabilities .getBrowserName ();
70+ "Browser-" + capabilities .getBrowserName (),
71+ capabilities .getBrowserName () );
11172 this .pullVideoRecordingContainerOnWarmUp =
11273 config .recordingMode () != BrowserWebDriverContainer .RecordingMode .SKIP ;
11374 }
11475
76+ @ SuppressWarnings ("checkstyle:MagicNumber" )
77+ public static BrowserTCI createDefaultBrowserTCI (
78+ final SeleniumBrowserWebDriverContainer c ,
79+ final String networkAlias ,
80+ final MutableCapabilities capabilities ,
81+ final BrowserTCIFactoryConfig config )
82+ {
83+ return new BrowserTCI (c , networkAlias , capabilities )
84+ .withBidiEnabled (config .bidiEnabled ())
85+ .withDeactivateCDPIfPossible (config .deactivateCdpIfPossible ())
86+ .withClientConfig (ClientConfig .defaultConfig ()
87+ .readTimeout (Duration .ofSeconds (60 + cpuSlownessFactor () * 10L )))
88+ .withWebDriverRetryCount (Math .max (Math .min (cpuSlownessFactor (), 5 ), 1 ))
89+ .withWebDriverRetrySec (25 + cpuSlownessFactor () * 5 )
90+ .withBrowserConsoleLog (
91+ logBrowserConsoleConsumer (config .browserConsoleLogLevel ()),
92+ config .browserConsoleLogLevel ().logLevels ());
93+ }
94+
95+ @ SuppressWarnings ({"resource" , "checkstyle:MagicNumber" })
96+ public static SeleniumBrowserWebDriverContainer createDefaultContainer (
97+ final MutableCapabilities capabilities ,
98+ final BrowserTCIFactoryConfig config )
99+ {
100+ return new SeleniumBrowserWebDriverContainer (capabilities )
101+ .withStartRecordingContainerManually (true )
102+ .withRecordingDirectory (config .dirForRecords ())
103+ .withRecordingMode (config .recordingMode ())
104+ // 2024-04 VNC is no longer required when recording
105+ .withDisableVNC (!config .vncEnabled ())
106+ .withEnableNoVNC (config .vncEnabled ())
107+ .withRecordingContainerSupplier (t -> new SeleniumRecordingContainer (t )
108+ .withFrameRate (10 )
109+ .withLogConsumer (getLogConsumer ("container.browserrecorder." + capabilities .getBrowserName ()))
110+ .withCreateContainerCmdModifier (cmd -> cmd .getHostConfig ().withMemory (ContainerMemory .M512M )))
111+ // Without that a mount volume dialog shows up
112+ // https://github.com/testcontainers/testcontainers-java/issues/1670
113+ .withSharedMemorySize (ContainerMemory .M2G )
114+ .withCreateContainerCmdModifier (cmd -> cmd .getHostConfig ().withMemory (ContainerMemory .M1G ))
115+ .withEnv ("SE_SCREEN_WIDTH" , "1600" )
116+ .withEnv ("SE_SCREEN_HEIGHT" , "900" )
117+ // By default after 5 mins the session is killed and you can't use the container anymore. Cool or?
118+ // https://github.com/SeleniumHQ/docker-selenium?tab=readme-ov-file#grid-url-and-session-timeout
119+ .withEnv ("SE_NODE_SESSION_TIMEOUT" , "3600" )
120+ // Disable local tracing, as we don't need it
121+ // https://github.com/SeleniumHQ/docker-selenium/issues/2355
122+ .withEnv ("SE_ENABLE_TRACING" , "false" )
123+ // Some (AWS) CPUs are completely overloaded with the default 15s timeout -> increase it
124+ .waitingFor (new WaitAllStrategy ()
125+ .withStrategy (new LogMessageWaitStrategy ()
126+ .withRegEx (".*(Started Selenium Standalone).*\n " )
127+ .withStartupTimeout (Duration .ofSeconds (30 + 20L * cpuSlownessFactor ())))
128+ .withStrategy (new HostPortWaitStrategy ())
129+ .withStartupTimeout (Duration .ofSeconds (30 + 20L * cpuSlownessFactor ())));
130+ }
131+
115132 public BrowserTCIFactory (
116133 final BiFunction <SeleniumBrowserWebDriverContainer , String , BrowserTCI > infraBuilder ,
117134 final Supplier <SeleniumBrowserWebDriverContainer > containerBuilder ,
0 commit comments