or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

application-launching.mdbrowser-configuration.mddevtools-protocol.mdindex.mdmedia-casting.mdnetwork-conditions.mdpermissions-management.mdservice-management.mdwebdriver-operations.md

permissions-management.mddocs/

0

# Permissions Management

1

2

Browser permissions management allows control over web API access including camera, microphone, geolocation, notifications, and other browser permissions for comprehensive testing scenarios.

3

4

## Permission Control

5

6

### Set Permission

7

8

Grant or deny specific browser permissions.

9

10

```java { .api }

11

public void setPermission(String name, String value);

12

```

13

14

**Parameters:**

15

- `name` (String): Permission name to control

16

- `value` (String): Permission state ("granted", "denied", "prompt")

17

18

**Usage Example:**

19

```java

20

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

21

22

// Grant camera permission

23

driver.setPermission("camera", "granted");

24

25

// Deny microphone permission

26

driver.setPermission("microphone", "denied");

27

28

// Set geolocation to prompt user

29

driver.setPermission("geolocation", "prompt");

30

```

31

32

## Common Permissions

33

34

### Media Permissions

35

36

Control access to camera and microphone:

37

38

```java

39

// Grant camera access

40

driver.setPermission("camera", "granted");

41

42

// Grant microphone access

43

driver.setPermission("microphone", "granted");

44

45

// Deny both camera and microphone

46

driver.setPermission("camera", "denied");

47

driver.setPermission("microphone", "denied");

48

49

// Test media permissions

50

driver.get("https://webrtc-test-site.com");

51

// Application can now access camera/microphone based on permissions set

52

```

53

54

### Location Services

55

56

Control geolocation API access:

57

58

```java

59

// Grant location access

60

driver.setPermission("geolocation", "granted");

61

62

// Test location-aware application

63

driver.get("https://maps-application.com");

64

// Application can access user location

65

66

// Deny location access

67

driver.setPermission("geolocation", "denied");

68

driver.get("https://maps-application.com");

69

// Application will be denied location access

70

```

71

72

### Notification Permissions

73

74

Control web notification access:

75

76

```java

77

// Grant notification permission

78

driver.setPermission("notifications", "granted");

79

80

// Test notification functionality

81

driver.get("https://notification-app.com");

82

WebElement enableNotificationsBtn = driver.findElement(By.id("enable-notifications"));

83

enableNotificationsBtn.click();

84

// Notifications will be allowed without user prompt

85

86

// Deny notifications

87

driver.setPermission("notifications", "denied");

88

```

89

90

### Clipboard Permissions

91

92

Control clipboard API access:

93

94

```java

95

// Grant clipboard read/write access

96

driver.setPermission("clipboard-read", "granted");

97

driver.setPermission("clipboard-write", "granted");

98

99

// Test clipboard functionality

100

driver.get("https://clipboard-app.com");

101

// Application can read from and write to system clipboard

102

103

// Deny clipboard access

104

driver.setPermission("clipboard-read", "denied");

105

driver.setPermission("clipboard-write", "denied");

106

```

107

108

## Permission States

109

110

### Available Permission Values

111

112

- **"granted"**: Permission is allowed without user prompt

113

- **"denied"**: Permission is explicitly denied

114

- **"prompt"**: Browser will prompt user for permission (default behavior)

115

116

```java

117

// Explicit permission granting

118

driver.setPermission("camera", "granted"); // Always allow

119

driver.setPermission("microphone", "denied"); // Always deny

120

driver.setPermission("geolocation", "prompt"); // Ask user

121

```

122

123

## Comprehensive Permission Management

124

125

### Set Multiple Permissions

126

127

```java

128

public void configureMediaTestingPermissions(ChromiumDriver driver) {

129

// Configure for media testing

130

driver.setPermission("camera", "granted");

131

driver.setPermission("microphone", "granted");

132

driver.setPermission("notifications", "granted");

133

driver.setPermission("geolocation", "granted");

134

135

// Deny potentially disruptive permissions

136

driver.setPermission("persistent-storage", "denied");

137

driver.setPermission("background-sync", "denied");

138

}

139

140

public void configureRestrictivePermissions(ChromiumDriver driver) {

141

// Deny all sensitive permissions

142

driver.setPermission("camera", "denied");

143

driver.setPermission("microphone", "denied");

144

driver.setPermission("geolocation", "denied");

145

driver.setPermission("notifications", "denied");

146

driver.setPermission("clipboard-read", "denied");

147

driver.setPermission("clipboard-write", "denied");

148

}

149

```

150

151

### Test Permission Scenarios

152

153

```java

154

import org.openqa.selenium.support.ui.WebDriverWait;

155

import org.openqa.selenium.support.ui.ExpectedConditions;

156

157

public class PermissionTesting {

158

159

public void testCameraPermissionGranted() {

160

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

161

162

try {

163

// Grant camera permission

164

driver.setPermission("camera", "granted");

165

166

// Navigate to video chat application

167

driver.get("https://videochat-app.com");

168

169

// Click button to access camera

170

WebElement startVideoBtn = driver.findElement(By.id("start-video"));

171

startVideoBtn.click();

172

173

// Verify camera access works (no permission dialog)

174

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

175

WebElement videoElement = wait.until(

176

ExpectedConditions.presenceOfElementLocated(By.tagName("video"))

177

);

178

179

// Verify video stream is active

180

assertTrue(videoElement.isDisplayed());

181

182

} finally {

183

driver.quit();

184

}

185

}

186

187

public void testCameraPermissionDenied() {

188

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

189

190

try {

191

// Deny camera permission

192

driver.setPermission("camera", "denied");

193

194

// Navigate to video chat application

195

driver.get("https://videochat-app.com");

196

197

// Click button to access camera

198

WebElement startVideoBtn = driver.findElement(By.id("start-video"));

199

startVideoBtn.click();

200

201

// Verify error message is shown

202

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));

203

WebElement errorMsg = wait.until(

204

ExpectedConditions.presenceOfElementLocated(By.className("camera-error"))

205

);

206

207

assertTrue(errorMsg.getText().contains("Camera access denied"));

208

209

} finally {

210

driver.quit();

211

}

212

}

213

}

214

```

215

216

## Permission Command Integration

217

218

The permissions functionality integrates with ChromiumDriverCommandExecutor:

219

220

```java { .api }

221

// Command constant from AddHasPermissions

222

public static final String SET_PERMISSION = "setPermission";

223

```

224

225

## Common Permission Names

226

227

### Media Permissions

228

- `"camera"` - Camera access

229

- `"microphone"` - Microphone access

230

231

### Location Services

232

- `"geolocation"` - Location services access

233

234

### User Interface

235

- `"notifications"` - Web notifications

236

- `"fullscreen"` - Fullscreen API access

237

238

### Data Access

239

- `"clipboard-read"` - Read from clipboard

240

- `"clipboard-write"` - Write to clipboard

241

- `"persistent-storage"` - Persistent storage quota

242

243

### Background Operations

244

- `"background-sync"` - Background synchronization

245

- `"push-messaging"` - Push message reception

246

247

### Sensors (if supported)

248

- `"accelerometer"` - Device motion sensors

249

- `"gyroscope"` - Device orientation sensors

250

- `"magnetometer"` - Device compass sensors

251

252

## Testing Permission Flows

253

254

### Grant Permission Flow

255

256

```java

257

public void testPermissionGrantFlow() {

258

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

259

260

// Pre-grant permission to avoid user prompts

261

driver.setPermission("geolocation", "granted");

262

263

driver.get("https://location-app.com");

264

265

// Click "Get My Location" button

266

driver.findElement(By.id("get-location")).click();

267

268

// Verify location is obtained without permission dialog

269

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));

270

WebElement locationDisplay = wait.until(

271

ExpectedConditions.presenceOfElementLocated(By.id("current-location"))

272

);

273

274

assertFalse(locationDisplay.getText().isEmpty());

275

}

276

```

277

278

### Deny Permission Flow

279

280

```java

281

public void testPermissionDenyFlow() {

282

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

283

284

// Pre-deny permission

285

driver.setPermission("notifications", "denied");

286

287

driver.get("https://news-app.com");

288

289

// Click "Enable Notifications" button

290

driver.findElement(By.id("enable-notifications")).click();

291

292

// Verify appropriate error handling

293

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));

294

WebElement errorMessage = wait.until(

295

ExpectedConditions.presenceOfElementLocated(By.className("permission-denied"))

296

);

297

298

assertTrue(errorMessage.getText().contains("Notifications are blocked"));

299

}

300

```

301

302

## Error Handling

303

304

Permission operations may encounter these exceptions:

305

306

- **IllegalArgumentException**: When null permission name or value is provided

307

- **WebDriverException**: When permission setting fails

308

309

```java

310

try {

311

driver.setPermission("camera", "granted");

312

} catch (IllegalArgumentException e) {

313

System.err.println("Invalid permission parameters: " + e.getMessage());

314

} catch (WebDriverException e) {

315

System.err.println("Failed to set permission: " + e.getMessage());

316

}

317

```

318

319

## Best Practices

320

321

1. **Pre-configure Permissions**: Set permissions before navigating to applications that need them

322

2. **Test Both Scenarios**: Test both granted and denied permission scenarios

323

3. **Realistic Testing**: Test with permissions that match your target users' likely configurations

324

4. **Error Handling**: Verify applications handle permission denials gracefully

325

5. **Clean State**: Consider resetting permissions between tests for consistent results

326

6. **Browser Compatibility**: Different browsers may support different permission names

327

7. **User Experience**: Test the complete permission flow from the user's perspective

328

329

## Advanced Permission Testing

330

331

### Dynamic Permission Changes

332

333

```java

334

public void testDynamicPermissionChanges() {

335

ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");

336

337

// Start with permission granted

338

driver.setPermission("camera", "granted");

339

driver.get("https://video-app.com");

340

341

// Verify camera works

342

driver.findElement(By.id("start-camera")).click();

343

// ... verify camera functionality

344

345

// Dynamically revoke permission

346

driver.setPermission("camera", "denied");

347

348

// Verify application handles permission revocation

349

driver.findElement(By.id("start-camera")).click();

350

// ... verify error handling

351

}

352

```

353

354

### Permission Reset Utility

355

356

```java

357

public class PermissionUtils {

358

359

public static void resetAllPermissions(ChromiumDriver driver) {

360

String[] permissions = {

361

"camera", "microphone", "geolocation", "notifications",

362

"clipboard-read", "clipboard-write", "persistent-storage"

363

};

364

365

for (String permission : permissions) {

366

try {

367

driver.setPermission(permission, "prompt");

368

} catch (Exception e) {

369

System.err.println("Failed to reset permission: " + permission);

370

}

371

}

372

}

373

374

public static void grantMediaPermissions(ChromiumDriver driver) {

375

driver.setPermission("camera", "granted");

376

driver.setPermission("microphone", "granted");

377

}

378

379

public static void denyAllPermissions(ChromiumDriver driver) {

380

driver.setPermission("camera", "denied");

381

driver.setPermission("microphone", "denied");

382

driver.setPermission("geolocation", "denied");

383

driver.setPermission("notifications", "denied");

384

}

385

}

386

```

387

388

This comprehensive permissions management system enables thorough testing of web applications under various permission scenarios, ensuring robust handling of user privacy controls.