or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

browser-container.mdindex.mdselenium-utils.mdvideo-recording.md

video-recording.mddocs/

0

# Video Recording

1

2

The Selenium module provides VNC-based video recording capabilities for test sessions. This allows you to capture browser interactions during tests for debugging and documentation purposes.

3

4

## Imports

5

6

```java

7

import org.testcontainers.containers.BrowserWebDriverContainer;

8

import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode;

9

import org.testcontainers.containers.VncRecordingContainer.VncRecordingFormat;

10

import org.testcontainers.containers.RecordingFileFactory;

11

import org.testcontainers.containers.DefaultRecordingFileFactory;

12

import java.io.File;

13

```

14

15

## Recording Configuration

16

17

### Basic Recording Mode

18

19

Configure video recording with a recording mode and output directory.

20

21

```java { .api }

22

public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory);

23

```

24

25

**Parameters:**

26

- `recordingMode`: When to record videos (SKIP, RECORD_ALL, RECORD_FAILING)

27

- `vncRecordingDirectory`: Directory where recording files will be saved

28

29

**Usage:**

30

```java

31

File recordingDir = new File("./test-recordings");

32

BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()

33

.withCapabilities(new ChromeOptions())

34

.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_FAILING, recordingDir);

35

```

36

37

### Advanced Recording Mode

38

39

Configure video recording with format specification.

40

41

```java { .api }

42

public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory, VncRecordingFormat recordingFormat);

43

```

44

45

**Parameters:**

46

- `recordingMode`: When to record videos

47

- `vncRecordingDirectory`: Directory for recording files

48

- `recordingFormat`: Video format (typically FLV)

49

50

**Usage:**

51

```java

52

File recordingDir = new File("./test-recordings");

53

BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()

54

.withCapabilities(new ChromeOptions())

55

.withRecordingMode(

56

BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL,

57

recordingDir,

58

VncRecordingContainer.VncRecordingFormat.FLV

59

);

60

```

61

62

## VncRecordingFormat Enum

63

64

```java { .api }

65

public enum VncRecordingFormat {

66

FLV("flv"),

67

MP4("mp4");

68

69

public String getFilenameExtension();

70

}

71

```

72

73

**Values:**

74

- `FLV`: Flash Video format (default)

75

- `MP4`: MPEG-4 format with H.264 encoding

76

77

The enum provides file extension information for proper recording file naming.

78

79

## Recording Modes

80

81

### VncRecordingMode Enum

82

83

```java { .api }

84

public enum VncRecordingMode {

85

SKIP,

86

RECORD_ALL,

87

RECORD_FAILING

88

}

89

```

90

91

**Values:**

92

- `SKIP`: No video recording

93

- `RECORD_ALL`: Record all test sessions regardless of outcome

94

- `RECORD_FAILING`: Record only failing test sessions

95

96

**Usage:**

97

```java

98

import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode;

99

100

// Record only failing tests

101

.withRecordingMode(VncRecordingMode.RECORD_FAILING, recordingDir)

102

103

// Record all tests

104

.withRecordingMode(VncRecordingMode.RECORD_ALL, recordingDir)

105

106

// Disable recording

107

.withRecordingMode(VncRecordingMode.SKIP, recordingDir)

108

```

109

110

## Recording File Management

111

112

### Custom Recording File Factory

113

114

Configure custom file naming for recording files.

115

116

```java { .api }

117

public SELF withRecordingFileFactory(RecordingFileFactory recordingFileFactory);

118

```

119

120

**Parameters:**

121

- `recordingFileFactory`: Custom implementation of RecordingFileFactory

122

123

**Usage:**

124

```java

125

RecordingFileFactory customFactory = new CustomRecordingFileFactory();

126

BrowserWebDriverContainer<?> chrome = new BrowserWebDriverContainer<>()

127

.withRecordingFileFactory(customFactory);

128

```

129

130

## RecordingFileFactory Interface

131

132

### File Creation Methods

133

134

```java { .api }

135

public interface RecordingFileFactory {

136

File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded);

137

138

default File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded, VncRecordingFormat recordingFormat) {

139

return recordingFileForTest(vncRecordingDirectory, prefix, succeeded);

140

}

141

142

@Deprecated

143

default File recordingFileForTest(File vncRecordingDirectory, Description description, boolean succeeded) {

144

return recordingFileForTest(vncRecordingDirectory,

145

description.getTestClass().getSimpleName() + "-" + description.getMethodName(),

146

succeeded);

147

}

148

}

149

```

150

151

**Parameters:**

152

- `vncRecordingDirectory`: Directory for saving recordings

153

- `prefix`: Test name prefix for the file

154

- `succeeded`: Whether the test passed or failed

155

- `recordingFormat`: Video format for the recording

156

- `description`: JUnit test description (deprecated method)

157

158

## Default Recording File Factory

159

160

### DefaultRecordingFileFactory

161

162

The default implementation creates timestamped files with test results.

163

164

```java { .api }

165

public class DefaultRecordingFileFactory implements RecordingFileFactory {

166

public File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded);

167

public File recordingFileForTest(File vncRecordingDirectory, String prefix, boolean succeeded, VncRecordingFormat recordingFormat);

168

}

169

```

170

171

**File Naming Pattern:**

172

```

173

{RESULT}-{PREFIX}-{TIMESTAMP}.{EXTENSION}

174

```

175

176

Where:

177

- `RESULT`: "PASSED" or "FAILED"

178

- `PREFIX`: Test name or custom prefix

179

- `TIMESTAMP`: "YYYYMMDD-HHmmss" format

180

- `EXTENSION`: File extension based on recording format

181

182

**Example Output:**

183

```

184

FAILED-ChromeWebDriverContainerTest-testLogin-20231201-143052.flv

185

PASSED-FirefoxTest-testNavigation-20231201-143105.flv

186

```

187

188

### File Naming Constants

189

190

The DefaultRecordingFileFactory uses internal constants for file naming:

191

- Result markers: "PASSED" for successful tests, "FAILED" for failed tests

192

- Filename format pattern: "{RESULT}-{PREFIX}-{TIMESTAMP}.{EXTENSION}"

193

194

## VNC Access Information

195

196

### Deprecated Access Methods

197

198

```java { .api }

199

@Deprecated

200

public String getPassword();

201

202

@Deprecated

203

public int getPort();

204

```

205

206

**Note:** Use `getVncAddress()` from BrowserWebDriverContainer instead.

207

208

**Default Values:**

209

- VNC Password: "secret"

210

- VNC Port: 5900

211

212

## Recording Integration

213

214

Video recording automatically integrates with test lifecycle:

215

216

1. **Test Start**: If recording mode is enabled, VNC recording container starts

217

2. **Test Execution**: Browser actions are captured via VNC

218

3. **Test End**: Recording is processed based on test result and recording mode

219

4. **File Creation**: Recording file is created using the configured RecordingFileFactory

220

221

The recording files are automatically saved to the specified directory with meaningful names that include test results and timestamps.