|
16 | 16 | ProfileConfiguration, |
17 | 17 | ProxyConfiguration, |
18 | 18 | ProxyCredentials, |
| 19 | + SessionConfiguration, |
19 | 20 | ViewportConfiguration, |
20 | 21 | ) |
21 | 22 |
|
@@ -1359,3 +1360,87 @@ def test_browser_session_accepts_dataclass_params(self, mock_client_class): |
1359 | 1360 | profile_configuration=profile, |
1360 | 1361 | ) |
1361 | 1362 | mock_client.stop.assert_called_once() |
| 1363 | + |
| 1364 | + @patch("bedrock_agentcore.tools.browser_client.BrowserClient") |
| 1365 | + def test_browser_session_context_manager_with_name(self, mock_client_class): |
| 1366 | + # Arrange |
| 1367 | + mock_client = MagicMock() |
| 1368 | + mock_client_class.return_value = mock_client |
| 1369 | + |
| 1370 | + # Act |
| 1371 | + with browser_session("us-west-2", name="my-session"): |
| 1372 | + pass |
| 1373 | + |
| 1374 | + # Assert |
| 1375 | + mock_client_class.assert_called_once_with("us-west-2") |
| 1376 | + mock_client.start.assert_called_once_with(name="my-session") |
| 1377 | + mock_client.stop.assert_called_once() |
| 1378 | + |
| 1379 | + @patch("bedrock_agentcore.tools.browser_client.BrowserClient") |
| 1380 | + def test_browser_session_context_manager_with_name_and_all_params(self, mock_client_class): |
| 1381 | + # Arrange |
| 1382 | + mock_client = MagicMock() |
| 1383 | + mock_client_class.return_value = mock_client |
| 1384 | + viewport = {"width": 1280, "height": 720} |
| 1385 | + proxy_config = { |
| 1386 | + "proxies": [ |
| 1387 | + { |
| 1388 | + "externalProxy": { |
| 1389 | + "server": "proxy.example.com", |
| 1390 | + "port": 8080, |
| 1391 | + } |
| 1392 | + } |
| 1393 | + ], |
| 1394 | + } |
| 1395 | + extensions = [{"location": {"s3": {"bucket": "my-bucket", "prefix": "extensions/my-ext"}}}] |
| 1396 | + profile_config = {"profileIdentifier": "my-profile-id"} |
| 1397 | + |
| 1398 | + # Act |
| 1399 | + with browser_session( |
| 1400 | + "us-west-2", |
| 1401 | + viewport=viewport, |
| 1402 | + identifier="custom-browser", |
| 1403 | + name="my-named-session", |
| 1404 | + proxy_configuration=proxy_config, |
| 1405 | + extensions=extensions, |
| 1406 | + profile_configuration=profile_config, |
| 1407 | + ): |
| 1408 | + pass |
| 1409 | + |
| 1410 | + # Assert |
| 1411 | + mock_client_class.assert_called_once_with("us-west-2") |
| 1412 | + mock_client.start.assert_called_once_with( |
| 1413 | + viewport=viewport, |
| 1414 | + identifier="custom-browser", |
| 1415 | + name="my-named-session", |
| 1416 | + proxy_configuration=proxy_config, |
| 1417 | + extensions=extensions, |
| 1418 | + profile_configuration=profile_config, |
| 1419 | + ) |
| 1420 | + mock_client.stop.assert_called_once() |
| 1421 | + |
| 1422 | + def test_session_configuration_with_name(self): |
| 1423 | + # Arrange |
| 1424 | + config = SessionConfiguration(name="test") |
| 1425 | + |
| 1426 | + # Act |
| 1427 | + result = config.to_dict() |
| 1428 | + |
| 1429 | + # Assert |
| 1430 | + assert result == {"name": "test"} |
| 1431 | + |
| 1432 | + def test_session_configuration_with_name_and_viewport(self): |
| 1433 | + # Arrange |
| 1434 | + config = SessionConfiguration( |
| 1435 | + name="test-session", |
| 1436 | + viewport=ViewportConfiguration(width=1920, height=1080), |
| 1437 | + ) |
| 1438 | + |
| 1439 | + # Act |
| 1440 | + result = config.to_dict() |
| 1441 | + |
| 1442 | + # Assert |
| 1443 | + assert result == { |
| 1444 | + "name": "test-session", |
| 1445 | + "viewport": {"width": 1920, "height": 1080}, |
| 1446 | + } |
0 commit comments