or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

browser-configuration.mddriver-information.mdindex.mdservice-management.mdwebdriver-implementation.md

driver-information.mddocs/

0

# Driver Information

1

2

WebDriver metadata and capability detection for automated driver selection, session creation, and multi-browser testing environments with Chrome-specific capability matching and availability checking.

3

4

## Capabilities

5

6

### ChromeDriverInfo Class

7

8

Provides metadata about Chrome WebDriver implementation for automated driver discovery and session management in multi-browser testing frameworks.

9

10

```java { .api }

11

/**

12

* WebDriverInfo implementation that provides metadata about ChromeDriver.

13

* Used by WebDriver managers for automatic driver selection and capability matching.

14

*/

15

public class ChromeDriverInfo implements WebDriverInfo {

16

17

/**

18

* Returns the display name for Chrome browser.

19

* @return "Chrome" as the human-readable browser name

20

*/

21

public String getDisplayName();

22

23

/**

24

* Returns the canonical capabilities that identify Chrome browser.

25

* @return ImmutableCapabilities with browser name set to "chrome"

26

*/

27

public Capabilities getCanonicalCapabilities();

28

29

/**

30

* Checks if the given capabilities are supported by ChromeDriver.

31

* @param capabilities The capabilities to check for support

32

* @return True if ChromeDriver can handle these capabilities, false otherwise

33

*/

34

public boolean isSupporting(Capabilities capabilities);

35

36

/**

37

* Checks if ChromeDriver is available on the current system.

38

* @return True if ChromeDriver executable can be found and started, false otherwise

39

*/

40

public boolean isAvailable();

41

42

/**

43

* Returns the maximum number of simultaneous sessions this driver can handle.

44

* Based on available processor cores plus one.

45

* @return Maximum concurrent Chrome sessions supported

46

*/

47

public int getMaximumSimultaneousSessions();

48

49

/**

50

* Creates a ChromeDriver instance with the given capabilities if supported.

51

* @param capabilities The capabilities for the new driver session

52

* @return Optional containing ChromeDriver if creation successful, empty otherwise

53

* @throws SessionNotCreatedException If session creation fails

54

*/

55

public Optional<WebDriver> createDriver(Capabilities capabilities) throws SessionNotCreatedException;

56

}

57

```

58

59

### Display Name

60

61

Get human-readable browser name for UI and logging purposes.

62

63

```java { .api }

64

/**

65

* Returns the display name for Chrome browser.

66

* Used in test reports, logs, and user interfaces.

67

* @return "Chrome" as the human-readable browser name

68

*/

69

public String getDisplayName();

70

```

71

72

**Usage Example:**

73

74

```java

75

ChromeDriverInfo info = new ChromeDriverInfo();

76

System.out.println("Browser: " + info.getDisplayName()); // Output: Browser: Chrome

77

```

78

79

### Canonical Capabilities

80

81

Get the standard capability set that identifies Chrome browser sessions.

82

83

```java { .api }

84

/**

85

* Returns the canonical capabilities that identify Chrome browser.

86

* Contains the minimal capability set for Chrome identification.

87

* @return ImmutableCapabilities with browser name set to "chrome"

88

*/

89

public Capabilities getCanonicalCapabilities();

90

```

91

92

**Usage Example:**

93

94

```java

95

ChromeDriverInfo info = new ChromeDriverInfo();

96

Capabilities canonical = info.getCanonicalCapabilities();

97

System.out.println("Browser name: " + canonical.getBrowserName()); // Output: chrome

98

```

99

100

### Capability Support Detection

101

102

Check if ChromeDriver can handle specific capability requirements.

103

104

```java { .api }

105

/**

106

* Checks if the given capabilities are supported by ChromeDriver.

107

* Looks for Chrome-specific capability markers:

108

* - browserName equals "chrome"

109

* - presence of "chromeOptions" capability

110

* - presence of "goog:chromeOptions" capability

111

* @param capabilities The capabilities to check for support

112

* @return True if ChromeDriver can handle these capabilities, false otherwise

113

*/

114

public boolean isSupporting(Capabilities capabilities);

115

```

116

117

**Usage Examples:**

118

119

```java

120

ChromeDriverInfo info = new ChromeDriverInfo();

121

122

// Test Chrome capabilities

123

DesiredCapabilities chromeCapabilities = new DesiredCapabilities();

124

chromeCapabilities.setBrowserName("chrome");

125

boolean supports = info.isSupporting(chromeCapabilities);

126

System.out.println("Supports Chrome: " + supports); // Output: true

127

128

// Test with ChromeOptions

129

ChromeOptions options = new ChromeOptions();

130

options.setHeadless(true);

131

boolean supportsOptions = info.isSupporting(options);

132

System.out.println("Supports ChromeOptions: " + supportsOptions); // Output: true

133

134

// Test Firefox capabilities

135

DesiredCapabilities firefoxCapabilities = new DesiredCapabilities();

136

firefoxCapabilities.setBrowserName("firefox");

137

boolean supportsFirefox = info.isSupporting(firefoxCapabilities);

138

System.out.println("Supports Firefox: " + supportsFirefox); // Output: false

139

```

140

141

### Availability Detection

142

143

Check if ChromeDriver is available and functional on the current system.

144

145

```java { .api }

146

/**

147

* Checks if ChromeDriver is available on the current system.

148

* Attempts to create a default ChromeDriverService to verify availability.

149

* @return True if ChromeDriver executable can be found and started, false otherwise

150

*/

151

public boolean isAvailable();

152

```

153

154

**Usage Example:**

155

156

```java

157

ChromeDriverInfo info = new ChromeDriverInfo();

158

159

if (info.isAvailable()) {

160

System.out.println("ChromeDriver is available");

161

// Proceed with Chrome testing

162

} else {

163

System.out.println("ChromeDriver not found - install ChromeDriver or set webdriver.chrome.driver property");

164

// Fall back to other browsers or skip Chrome tests

165

}

166

```

167

168

### Session Capacity

169

170

Determine the maximum number of concurrent Chrome sessions supported.

171

172

```java { .api }

173

/**

174

* Returns the maximum number of simultaneous sessions this driver can handle.

175

* Calculated as the number of available processor cores plus one.

176

* @return Maximum concurrent Chrome sessions supported

177

*/

178

public int getMaximumSimultaneousSessions();

179

```

180

181

**Usage Example:**

182

183

```java

184

ChromeDriverInfo info = new ChromeDriverInfo();

185

int maxSessions = info.getMaximumSimultaneousSessions();

186

System.out.println("Max Chrome sessions: " + maxSessions);

187

188

// Use for parallel test execution planning

189

if (maxSessions >= 4) {

190

// Run tests in parallel

191

System.out.println("Running tests with " + maxSessions + " parallel Chrome instances");

192

} else {

193

// Run tests sequentially

194

System.out.println("Limited to sequential Chrome testing");

195

}

196

```

197

198

### Driver Instance Creation

199

200

Create ChromeDriver instances with capability validation and error handling.

201

202

```java { .api }

203

/**

204

* Creates a ChromeDriver instance with the given capabilities if supported.

205

* Validates capabilities and system availability before attempting creation.

206

* @param capabilities The capabilities for the new driver session

207

* @return Optional containing ChromeDriver if creation successful, empty otherwise

208

* @throws SessionNotCreatedException If session creation fails

209

*/

210

public Optional<WebDriver> createDriver(Capabilities capabilities) throws SessionNotCreatedException;

211

```

212

213

**Usage Examples:**

214

215

```java

216

import java.util.Optional;

217

218

ChromeDriverInfo info = new ChromeDriverInfo();

219

220

// Create driver with basic capabilities

221

DesiredCapabilities capabilities = new DesiredCapabilities();

222

capabilities.setBrowserName("chrome");

223

224

Optional<WebDriver> driverOpt = info.createDriver(capabilities);

225

if (driverOpt.isPresent()) {

226

WebDriver driver = driverOpt.get();

227

driver.get("https://example.com");

228

System.out.println("Page title: " + driver.getTitle());

229

driver.quit();

230

} else {

231

System.out.println("Failed to create Chrome driver");

232

}

233

234

// Create driver with ChromeOptions

235

ChromeOptions options = new ChromeOptions();

236

options.setHeadless(true);

237

options.addArguments("--no-sandbox");

238

239

try {

240

Optional<WebDriver> chromeDriver = info.createDriver(options);

241

if (chromeDriver.isPresent()) {

242

// Driver created successfully

243

WebDriver driver = chromeDriver.get();

244

// Use driver...

245

driver.quit();

246

}

247

} catch (SessionNotCreatedException e) {

248

System.err.println("Failed to create Chrome session: " + e.getMessage());

249

}

250

```

251

252

### Integration with WebDriver Managers

253

254

Use ChromeDriverInfo with automated WebDriver management systems.

255

256

**Usage Example:**

257

258

```java

259

import org.openqa.selenium.WebDriverInfo;

260

import java.util.ServiceLoader;

261

import java.util.List;

262

import java.util.stream.Collectors;

263

264

public class DriverSelector {

265

public static WebDriver selectBestDriver(Capabilities desiredCapabilities) {

266

// Load all available WebDriverInfo implementations

267

ServiceLoader<WebDriverInfo> loader = ServiceLoader.load(WebDriverInfo.class);

268

269

List<WebDriverInfo> availableDrivers = loader.stream()

270

.map(ServiceLoader.Provider::get)

271

.filter(info -> info.isAvailable() && info.isSupporting(desiredCapabilities))

272

.collect(Collectors.toList());

273

274

// Find ChromeDriverInfo specifically

275

Optional<WebDriverInfo> chromeInfo = availableDrivers.stream()

276

.filter(info -> "Chrome".equals(info.getDisplayName()))

277

.findFirst();

278

279

if (chromeInfo.isPresent()) {

280

Optional<WebDriver> driver = chromeInfo.get().createDriver(desiredCapabilities);

281

if (driver.isPresent()) {

282

return driver.get();

283

}

284

}

285

286

throw new RuntimeException("No suitable Chrome driver found");

287

}

288

}

289

290

// Usage

291

DesiredCapabilities caps = new DesiredCapabilities();

292

caps.setBrowserName("chrome");

293

WebDriver driver = DriverSelector.selectBestDriver(caps);

294

```

295

296

### Testing Framework Integration

297

298

Integrate ChromeDriverInfo with testing frameworks for automated browser selection.

299

300

**TestNG/JUnit Example:**

301

302

```java

303

import org.testng.annotations.BeforeMethod;

304

import org.testng.annotations.AfterMethod;

305

306

public class CrossBrowserTest {

307

private WebDriver driver;

308

private ChromeDriverInfo chromeInfo = new ChromeDriverInfo();

309

310

@BeforeMethod

311

public void setupDriver() {

312

if (chromeInfo.isAvailable()) {

313

ChromeOptions options = new ChromeOptions();

314

if (isHeadlessEnvironment()) {

315

options.setHeadless(true);

316

}

317

318

Optional<WebDriver> chromeDriver = chromeInfo.createDriver(options);

319

if (chromeDriver.isPresent()) {

320

driver = chromeDriver.get();

321

} else {

322

throw new RuntimeException("Failed to create Chrome driver");

323

}

324

} else {

325

throw new RuntimeException("Chrome driver not available");

326

}

327

}

328

329

@AfterMethod

330

public void teardownDriver() {

331

if (driver != null) {

332

driver.quit();

333

}

334

}

335

336

private boolean isHeadlessEnvironment() {

337

return System.getenv("CI") != null || System.getProperty("headless") != null;

338

}

339

}

340

```

341

342

## Types

343

344

```java { .api }

345

// WebDriver information interface

346

interface WebDriverInfo {

347

String getDisplayName();

348

Capabilities getCanonicalCapabilities();

349

boolean isSupporting(Capabilities capabilities);

350

boolean isAvailable();

351

int getMaximumSimultaneousSessions();

352

Optional<WebDriver> createDriver(Capabilities capabilities) throws SessionNotCreatedException;

353

}

354

355

// Capability types

356

interface Capabilities {

357

String getBrowserName();

358

Object getCapability(String capabilityName);

359

// ... other capability methods

360

}

361

362

class ImmutableCapabilities implements Capabilities {

363

public ImmutableCapabilities(String key, Object value);

364

// ... implementation methods

365

}

366

367

class DesiredCapabilities implements Capabilities {

368

public void setBrowserName(String browserName);

369

public void setCapability(String key, Object value);

370

// ... other methods

371

}

372

373

// Optional wrapper for driver creation

374

class Optional<T> {

375

public static <T> Optional<T> empty();

376

public static <T> Optional<T> of(T value);

377

public boolean isPresent();

378

public T get();

379

}

380

381

// Exception types

382

class SessionNotCreatedException extends WebDriverException {

383

public SessionNotCreatedException(String message);

384

public SessionNotCreatedException(String message, Throwable cause);

385

}

386

```