-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom profile in playwright
if user_data_dir option is found in browser_option, then the launch function used is launch_persistent_context instead of launch and the user_data_dir option is passed to playwright
- Loading branch information
Showing
2 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/unit/browsers/test_playwright_browser_plugin_with_profile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import AsyncGenerator | ||
|
||
import pytest | ||
|
||
from crawlee.browsers import PlaywrightBrowserPlugin | ||
|
||
|
||
@pytest.fixture() | ||
async def plugin(tmp_path_factory) -> AsyncGenerator[PlaywrightBrowserPlugin, None]: | ||
browser_options = {'user_data_dir': tmp_path_factory.mktemp('data') / 'profile'} | ||
async with PlaywrightBrowserPlugin(browser_options=browser_options) as plugin: | ||
yield plugin | ||
|
||
|
||
async def test_new_browser(plugin: PlaywrightBrowserPlugin, httpbin: str) -> None: | ||
browser_controller = await plugin.new_browser() | ||
|
||
# assert browser_controller.is_browser_connected | ||
|
||
page = await browser_controller.new_page() | ||
await page.goto(f'{httpbin}') | ||
|
||
await page.close() | ||
await browser_controller.close() | ||
|
||
# assert not browser_controller.is_browser_connected | ||
# check if profile directory does contain some files | ||
assert any(Path(plugin.browser_options.get('user_data_dir')).iterdir()) |