0
# Browser Container Management
1
2
The `BrowserWebDriverContainer` class is the core component for creating and managing Selenium browser containers. It provides containerized instances of Chrome, Firefox, and Edge browsers with full configuration control.
3
4
## Imports
5
6
```java
7
import org.testcontainers.containers.BrowserWebDriverContainer;
8
import org.testcontainers.utility.DockerImageName;
9
import org.openqa.selenium.Capabilities;
10
import org.openqa.selenium.chrome.ChromeOptions;
11
import org.openqa.selenium.firefox.FirefoxOptions;
12
import org.openqa.selenium.edge.EdgeOptions;
13
import org.openqa.selenium.remote.RemoteWebDriver;
14
import java.net.URL;
15
```
16
17
## Container Creation
18
19
### Default Constructor
20
21
Creates a browser container with default Chrome configuration.
22
23
```java { .api }
24
public BrowserWebDriverContainer();
25
```
26
27
**Usage:**
28
```java
29
BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>();
30
```
31
32
### Custom Image Constructor
33
34
Creates a browser container with a specific Docker image.
35
36
```java { .api }
37
public BrowserWebDriverContainer(String dockerImageName);
38
public BrowserWebDriverContainer(DockerImageName dockerImageName);
39
```
40
41
**Parameters:**
42
- `dockerImageName`: Docker image name (e.g., "selenium/standalone-firefox:4.15.0")
43
44
**Usage:**
45
```java
46
// Using string image name
47
BrowserWebDriverContainer<?> firefox = new BrowserWebDriverContainer<>("selenium/standalone-firefox");
48
49
// Using DockerImageName
50
DockerImageName image = DockerImageName.parse("selenium/standalone-edge:4.15.0");
51
BrowserWebDriverContainer<?> edge = new BrowserWebDriverContainer<>(image);
52
```
53
54
## Browser Configuration
55
56
### Capabilities Configuration
57
58
Set browser-specific capabilities for the container.
59
60
```java { .api }
61
public SELF withCapabilities(Capabilities capabilities);
62
```
63
64
**Parameters:**
65
- `capabilities`: Selenium Capabilities object (ChromeOptions, FirefoxOptions, EdgeOptions)
66
67
**Usage:**
68
```java
69
ChromeOptions chromeOptions = new ChromeOptions();
70
chromeOptions.addArguments("--headless");
71
chromeOptions.addArguments("--no-sandbox");
72
73
BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()
74
.withCapabilities(chromeOptions);
75
```
76
77
### Deprecated Capabilities Method
78
79
```java { .api }
80
@Deprecated
81
public SELF withDesiredCapabilities(DesiredCapabilities capabilities);
82
```
83
84
**Note:** Use `withCapabilities(Capabilities)` instead.
85
86
## Container Access
87
88
### Selenium WebDriver Endpoint
89
90
Get the URL endpoint for connecting RemoteWebDriver instances.
91
92
```java { .api }
93
public URL getSeleniumAddress();
94
```
95
96
**Returns:** URL pointing to the Selenium WebDriver endpoint (typically http://host:port/wd/hub)
97
98
**Usage:**
99
```java
100
BrowserWebDriverContainer<?> container = new BrowserWebDriverContainer<>()
101
.withCapabilities(new ChromeOptions());
102
container.start();
103
104
URL seleniumUrl = container.getSeleniumAddress();
105
RemoteWebDriver driver = new RemoteWebDriver(seleniumUrl, new ChromeOptions());
106
```
107
108
### VNC Access
109
110
Get the VNC connection string for debugging and monitoring.
111
112
```java { .api }
113
public String getVncAddress();
114
```
115
116
**Returns:** VNC connection string (format: "vnc://vnc:secret@host:port")
117
118
**Usage:**
119
```java
120
String vncUrl = container.getVncAddress();
121
// Connect with VNC client: vnc://vnc:secret@localhost:32768
122
```
123
124
### Deprecated WebDriver Method
125
126
```java { .api }
127
@Deprecated
128
public synchronized RemoteWebDriver getWebDriver();
129
```
130
131
**Note:** Use `getSeleniumAddress()` to create your own RemoteWebDriver instances instead.
132
133
## Static Utility Methods
134
135
### Docker Image Selection
136
137
```java { .api }
138
@Deprecated
139
public static String getDockerImageForCapabilities(Capabilities capabilities, String seleniumVersion);
140
```
141
142
**Note:** This method is deprecated. Use the constructor with `withCapabilities()` instead.
143
144
## Supported Browser Images
145
146
The container supports the following browser images:
147
148
- **Chrome**: `selenium/standalone-chrome`, `selenium/standalone-chrome-debug`
149
- **Firefox**: `selenium/standalone-firefox`, `selenium/standalone-firefox-debug`
150
- **Edge**: `selenium/standalone-edge` (Selenium 4+ only)
151
152
## Container Lifecycle
153
154
The container integrates with JUnit test lifecycle:
155
156
```java { .api }
157
public void afterTest(TestDescription description, Optional<Throwable> throwable);
158
```
159
160
This method is automatically called when using JUnit rules and handles cleanup including video recording retention based on test results.
161
162
## Network Configuration
163
164
### Legacy Container Linking
165
166
```java { .api }
167
@Deprecated
168
public SELF withLinkToContainer(LinkableContainer otherContainer, String alias);
169
```
170
171
**Note:** Links are deprecated. Use Network features instead.
172
173
## Container Lifecycle and Management
174
175
### Container Stopping
176
177
The container properly manages resources during shutdown:
178
179
```java { .api }
180
public void stop();
181
```
182
183
This method automatically handles cleanup of both the browser container and any associated VNC recording containers.
184
185
### Test Integration
186
187
```java { .api }
188
public void afterTest(TestDescription description, Optional<Throwable> throwable);
189
```
190
191
Automatic integration with JUnit test lifecycle for proper cleanup and video recording management based on test results.
192
193
## Container Ports and Defaults
194
195
The container uses standard ports and defaults:
196
- **Selenium Port**: 4444 (default WebDriver endpoint port)
197
- **VNC Port**: 5900 (for VNC access and recording)
198
- **Default VNC Password**: "secret"
199
200
These values are used internally by the container and are accessible through the appropriate getter methods.