diff --git a/examples_async.py b/examples_async.py index 77427c5..ac9d962 100644 --- a/examples_async.py +++ b/examples_async.py @@ -24,6 +24,7 @@ async def test_chrome(chrome: AsyncChrome): assert ok is True, ok resp = await chrome.get_server('json') assert isinstance(resp.json(), list) + await chrome.new_tab() tabs1: List[AsyncTab] = await chrome.get_tabs() tabs2: List[AsyncTab] = await chrome.tabs assert tabs1 == tabs2 and tabs1 and tabs2, (tabs1, tabs2) @@ -313,18 +314,24 @@ async def test_iter_events(tab: AsyncTab): await tab.goto('http://httpbin.org/get', timeout=0) data = await events_iter assert data, data - async with tab.iter_events(['Page.loadEventFired'], - timeout=8) as events_iter: + await tab.goto('http://httpbin.org/get', timeout=0) data = await events_iter.get() assert data, data - async with tab.iter_events(['Page.loadEventFired'], - timeout=8) as events_iter: + await tab.goto('http://httpbin.org/get', timeout=0) async for data in events_iter: assert data break + def cb(event, tab, buffer): + return tab + + async with tab.iter_events({'Page.loadEventFired': cb}, + timeout=8) as events_iter: + await tab.goto('http://httpbin.org/get', timeout=0) + data = await events_iter + assert type(data) == type(tab), data # test iter_fetch async with tab.iter_fetch(patterns=[{ 'urlPattern': '*httpbin.org/get?a=*' @@ -393,12 +400,14 @@ async def cb(event, tab, buffer): async def test_port_forwarding(host, port): from ichrome.utils import PortForwarder - dst_port = port + 1000 + dst_port = port + 100 async with PortForwarder((host, port), (host, dst_port)): - r = await Requests().get(f'http://{host}:{dst_port}/json', timeout=2) - assert 'webSocketDebuggerUrl' in r.text - r = await Requests().get(f'http://{host}:{dst_port}/json', timeout=2) - assert 'webSocketDebuggerUrl' not in r.text + r = await Requests().get(f'http://{host}:{dst_port}/json/version', + timeout=5) + assert 'webSocketDebuggerUrl' in r.text, r.text + r = await Requests().get(f'http://{host}:{dst_port}/json/version', + timeout=5) + assert 'webSocketDebuggerUrl' not in r.text, r.text async def test_duplicated_key_error(tab: AsyncTab): diff --git a/ichrome/__init__.py b/ichrome/__init__.py index 5b31455..4984111 100644 --- a/ichrome/__init__.py +++ b/ichrome/__init__.py @@ -6,7 +6,7 @@ from .pool import ChromeEngine from .sync_utils import Chrome, Tab -__version__ = "3.0.9" +__version__ = "3.1.0" __tips__ = "[github]: https://github.com/ClericPy/ichrome\n[cdp]: https://chromedevtools.github.io/devtools-protocol/\n[cmd args]: https://peter.sh/experiments/chromium-command-line-switches/" __all__ = [ 'Chrome', 'ChromeDaemon', 'Tab', 'Tag', 'AsyncChrome', 'AsyncTab', 'logger',