|
34 | 34 | import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; |
35 | 35 | import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; |
36 | 36 | import org.testcontainers.containers.wait.strategy.WaitAllStrategy; |
| 37 | +import org.testcontainers.images.RemoteDockerImage; |
37 | 38 |
|
38 | 39 | import software.xdev.tci.concurrent.TCIExecutorServiceHolder; |
39 | 40 | import software.xdev.tci.factory.prestart.PreStartableTCIFactory; |
40 | 41 | import software.xdev.tci.factory.prestart.config.PreStartConfig; |
| 42 | +import software.xdev.tci.logging.JULtoSLF4JRedirector; |
41 | 43 | import software.xdev.tci.misc.ContainerMemory; |
42 | 44 | import software.xdev.tci.selenium.BrowserTCI; |
43 | 45 | import software.xdev.tci.selenium.containers.SeleniumBrowserWebDriverContainer; |
44 | 46 | import software.xdev.tci.selenium.factory.config.BrowserTCIFactoryConfig; |
45 | 47 | import software.xdev.tci.serviceloading.TCIServiceLoaderHolder; |
| 48 | +import software.xdev.testcontainers.selenium.containers.browser.BrowserWebDriverContainer; |
46 | 49 | import software.xdev.testcontainers.selenium.containers.recorder.SeleniumRecordingContainer; |
47 | 50 |
|
48 | 51 |
|
49 | 52 | public class BrowserTCIFactory extends PreStartableTCIFactory<SeleniumBrowserWebDriverContainer, BrowserTCI> |
50 | 53 | { |
| 54 | + protected static boolean warmupRecordingContainerPullStarted; |
| 55 | + protected boolean pullVideoRecordingContainerOnWarmUp; |
51 | 56 | protected final String browserName; |
52 | 57 |
|
53 | 58 | public BrowserTCIFactory(final MutableCapabilities capabilities) |
@@ -103,6 +108,8 @@ public BrowserTCIFactory(final MutableCapabilities capabilities, final BrowserTC |
103 | 108 | "container.browserwebdriver." + capabilities.getBrowserName(), |
104 | 109 | "Browser-" + capabilities.getBrowserName()); |
105 | 110 | this.browserName = capabilities.getBrowserName(); |
| 111 | + this.pullVideoRecordingContainerOnWarmUp = |
| 112 | + config.recordingMode() != BrowserWebDriverContainer.RecordingMode.SKIP; |
106 | 113 | } |
107 | 114 |
|
108 | 115 | public BrowserTCIFactory( |
@@ -132,6 +139,53 @@ public BrowserTCIFactory( |
132 | 139 | this.browserName = browserName; |
133 | 140 | } |
134 | 141 |
|
| 142 | + public BrowserTCIFactory withPullVideoRecordingContainerOnWarmUp(final boolean pull) |
| 143 | + { |
| 144 | + this.pullVideoRecordingContainerOnWarmUp = pull; |
| 145 | + return this; |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + protected void warmUpInternal() |
| 150 | + { |
| 151 | + // Selenium uses JUL |
| 152 | + JULtoSLF4JRedirector.redirect(); |
| 153 | + |
| 154 | + this.pullRecordingContainerOnWarmUpAsync(); |
| 155 | + } |
| 156 | + |
| 157 | + protected void pullRecordingContainerOnWarmUpAsync() |
| 158 | + { |
| 159 | + if(this.pullVideoRecordingContainerOnWarmUp) |
| 160 | + { |
| 161 | + pullRecordingContainerOnWarmUpAsyncDefault(); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + protected static synchronized void pullRecordingContainerOnWarmUpAsyncDefault() |
| 166 | + { |
| 167 | + if(warmupRecordingContainerPullStarted) |
| 168 | + { |
| 169 | + return; |
| 170 | + } |
| 171 | + |
| 172 | + CompletableFuture.runAsync( |
| 173 | + () -> { |
| 174 | + try |
| 175 | + { |
| 176 | + new RemoteDockerImage(SeleniumRecordingContainer.DEFAULT_IMAGE).get(10, TimeUnit.MINUTES); |
| 177 | + } |
| 178 | + catch(final Exception e) |
| 179 | + { |
| 180 | + LoggerFactory.getLogger(BrowserTCIFactory.class) |
| 181 | + .warn("Failed to pull {}", SeleniumRecordingContainer.DEFAULT_IMAGE, e); |
| 182 | + } |
| 183 | + }, |
| 184 | + TCIExecutorServiceHolder.instance()); |
| 185 | + |
| 186 | + warmupRecordingContainerPullStarted = true; |
| 187 | + } |
| 188 | + |
135 | 189 | protected static Consumer<String> logBrowserConsoleConsumer(final BrowserConsoleLogLevel level) |
136 | 190 | { |
137 | 191 | if(!level.active()) |
|
0 commit comments