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

webdriver-implementation.mddocs/

0

# WebDriver Implementation

1

2

Core Chrome WebDriver functionality providing browser automation, navigation, element interaction, session management, and Chrome-specific features like app launching and geolocation.

3

4

## Capabilities

5

6

### ChromeDriver Class

7

8

Main WebDriver implementation that controls Chrome browser instances with support for local storage, geolocation, touch interactions, and network connection management.

9

10

```java { .api }

11

/**

12

* A WebDriver implementation that controls a Chrome browser running on the local machine.

13

* Extends RemoteWebDriver with Chrome-specific functionality.

14

*/

15

public class ChromeDriver extends RemoteWebDriver

16

implements LocationContext, WebStorage, HasTouchScreen, NetworkConnection {

17

18

/**

19

* Creates a new ChromeDriver using the default server configuration.

20

*/

21

public ChromeDriver();

22

23

/**

24

* Creates a new ChromeDriver instance. The service will be started along with the driver,

25

* and shutdown upon calling quit().

26

* @param service The service to use

27

*/

28

public ChromeDriver(ChromeDriverService service);

29

30

/**

31

* Creates a new ChromeDriver instance with the specified options.

32

* @param options The options to use

33

*/

34

public ChromeDriver(ChromeOptions options);

35

36

/**

37

* Creates a new ChromeDriver instance with the specified options. The service will be

38

* started along with the driver, and shutdown upon calling quit().

39

* @param service The service to use

40

* @param options The options to use

41

*/

42

public ChromeDriver(ChromeDriverService service, ChromeOptions options);

43

44

/**

45

* Creates a new ChromeDriver instance with capabilities (deprecated).

46

* @param capabilities The capabilities required from the ChromeDriver

47

* @deprecated Use ChromeDriver(ChromeOptions) instead

48

*/

49

@Deprecated

50

public ChromeDriver(Capabilities capabilities);

51

52

/**

53

* Creates a new ChromeDriver instance with service and capabilities (deprecated).

54

* @param service The service to use

55

* @param capabilities The capabilities required from the ChromeDriver

56

* @deprecated Use ChromeDriver(ChromeDriverService, ChromeOptions) instead

57

*/

58

@Deprecated

59

public ChromeDriver(ChromeDriverService service, Capabilities capabilities);

60

}

61

```

62

63

**Usage Examples:**

64

65

```java

66

import org.openqa.selenium.chrome.ChromeDriver;

67

import org.openqa.selenium.chrome.ChromeOptions;

68

import org.openqa.selenium.chrome.ChromeDriverService;

69

import org.openqa.selenium.WebDriver;

70

71

// Basic usage with default configuration

72

WebDriver driver = new ChromeDriver();

73

74

// With custom options

75

ChromeOptions options = new ChromeOptions();

76

options.setHeadless(true);

77

WebDriver driver = new ChromeDriver(options);

78

79

// With custom service

80

ChromeDriverService service = ChromeDriverService.createDefaultService();

81

WebDriver driver = new ChromeDriver(service);

82

83

// Full configuration

84

ChromeDriverService service = new ChromeDriverService.Builder()

85

.usingAnyFreePort()

86

.withVerbose(true)

87

.build();

88

ChromeOptions options = new ChromeOptions();

89

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

90

WebDriver driver = new ChromeDriver(service, options);

91

```

92

93

### File Detection

94

95

Chrome-specific file detection handling for remote WebDriver scenarios.

96

97

```java { .api }

98

/**

99

* Throws WebDriverException as file detection is not supported for local ChromeDriver.

100

* @param detector The file detector to set

101

* @throws WebDriverException Always thrown for local ChromeDriver instances

102

*/

103

public void setFileDetector(FileDetector detector);

104

```

105

106

### Local Storage Access

107

108

HTML5 local storage interface for persisting data in the browser.

109

110

```java { .api }

111

/**

112

* Gets the local storage interface for the current session.

113

* @return LocalStorage interface for storing key-value pairs

114

*/

115

public LocalStorage getLocalStorage();

116

```

117

118

### Session Storage Access

119

120

HTML5 session storage interface for temporary data storage.

121

122

```java { .api }

123

/**

124

* Gets the session storage interface for the current session.

125

* @return SessionStorage interface for storing temporary key-value pairs

126

*/

127

public SessionStorage getSessionStorage();

128

```

129

130

### Geolocation Support

131

132

Geolocation API for getting and setting browser location coordinates.

133

134

```java { .api }

135

/**

136

* Gets the current geolocation of the browser.

137

* @return Current Location with latitude, longitude, and altitude

138

*/

139

public Location location();

140

141

/**

142

* Sets the geolocation of the browser.

143

* @param location The location to set with coordinates

144

*/

145

public void setLocation(Location location);

146

```

147

148

**Usage Example:**

149

150

```java

151

import org.openqa.selenium.html5.Location;

152

153

// Get current location

154

Location currentLocation = ((ChromeDriver) driver).location();

155

System.out.println("Lat: " + currentLocation.getLatitude());

156

System.out.println("Lng: " + currentLocation.getLongitude());

157

158

// Set new location

159

Location newLocation = new Location(37.7749, -122.4194, 0); // San Francisco

160

((ChromeDriver) driver).setLocation(newLocation);

161

```

162

163

### Touch Screen Interface

164

165

Touch screen interaction support for mobile testing scenarios.

166

167

```java { .api }

168

/**

169

* Gets the touch screen interface for performing touch interactions.

170

* @return TouchScreen interface for touch gestures and interactions

171

*/

172

public TouchScreen getTouch();

173

```

174

175

### Network Connection Management

176

177

Network connection type management for simulating different network conditions.

178

179

```java { .api }

180

/**

181

* Gets the current network connection type.

182

* @return Current ConnectionType (WIFI, CELL_4G, etc.)

183

*/

184

public ConnectionType getNetworkConnection();

185

186

/**

187

* Sets the network connection type for testing different network scenarios.

188

* @param type The connection type to simulate

189

* @return The connection type that was set

190

*/

191

public ConnectionType setNetworkConnection(ConnectionType type);

192

```

193

194

### Chrome App Launching

195

196

Chrome-specific functionality for launching Chrome apps by application ID.

197

198

```java { .api }

199

/**

200

* Launches Chrome app specified by id.

201

* @param id Chrome app id to launch

202

*/

203

public void launchApp(String id);

204

```

205

206

**Usage Example:**

207

208

```java

209

// Launch a Chrome app

210

ChromeDriver chromeDriver = (ChromeDriver) driver;

211

chromeDriver.launchApp("app_id_here");

212

```

213

214

## Types

215

216

```java { .api }

217

// Connection types for network simulation

218

enum ConnectionType {

219

NONE, AIRPLANE, WIFI, CELL_2G, CELL_3G, CELL_4G

220

}

221

222

// Location for geolocation API

223

class Location {

224

public Location(double latitude, double longitude, double altitude);

225

public double getLatitude();

226

public double getLongitude();

227

public double getAltitude();

228

}

229

230

// Storage interfaces

231

interface LocalStorage {

232

void setItem(String key, String value);

233

String getItem(String key);

234

void removeItem(String key);

235

void clear();

236

Set<String> keySet();

237

}

238

239

interface SessionStorage {

240

void setItem(String key, String value);

241

String getItem(String key);

242

void removeItem(String key);

243

void clear();

244

Set<String> keySet();

245

}

246

247

// Touch interface

248

interface TouchScreen {

249

void singleTap(Coordinates where);

250

void down(int x, int y);

251

void up(int x, int y);

252

void move(int x, int y);

253

void scroll(Coordinates where, int xOffset, int yOffset);

254

void doubleTap(Coordinates where);

255

void longPress(Coordinates where);

256

}

257

```