Skip to content

Commit

Permalink
update test demo for new version chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
lidong committed Mar 3, 2023
1 parent 5b15c91 commit ab15e38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions examples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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=*'
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ichrome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ab15e38

Please sign in to comment.