diff --git a/examples_async.py b/examples_async.py index 681c18c..43aa74f 100644 --- a/examples_async.py +++ b/examples_async.py @@ -662,7 +662,6 @@ def test_all(): time.sleep(1) finally: loop.close() - AsyncChromeDaemon.clear_dir(AsyncChromeDaemon.DEFAULT_USER_DIR_PATH) if __name__ == "__main__": diff --git a/examples_debug.py b/examples_debug.py index ed72218..aa36bf1 100644 --- a/examples_debug.py +++ b/examples_debug.py @@ -1,26 +1,22 @@ import time from ichrome import AsyncTab -from ichrome.debugger import get_a_tab, network_sniffer, launch +from ichrome.debugger import Chrome, Daemon # There are 3 ways to create a daemon # 1. get_a_tab: auto find the existing Chrome (launched before like python -m ichrome), or create a new daemon # 2. daemon = Daemon() # 3. daemon = launch() -# type hints for autocomplete in the IDE -daemon = launch() -tab: AsyncTab = get_a_tab() - -def test_set_ua(): +def test_set_ua(tab: AsyncTab): # check the UA changed - tab.set_ua("No UA.") + tab.set_ua("Custom UA.") tab.set_url("http://httpbin.org/user-agent") - assert "No UA." in tab.html, tab.html + assert "Custom UA." in tab.html, tab.html -def test_mouse_keyboard(): +def test_mouse_keyboard(tab: AsyncTab): # click the input element and send some string tab.set_url("http://httpbin.org/forms/post", timeout=5) rect: dict = tab.get_bounding_client_rect('[type="email"]') @@ -28,35 +24,39 @@ def test_mouse_keyboard(): tab.keyboard_send(string="123@1.com") # click the submit button tab.click("button") - tab.wait_loading(2) + tab.wait_loading(3) assert '"custemail": "123@1.com"' in tab.html, tab.html -def test_js(): - tab.set_url("https://postman-echo.com/ip") - tag = tab.querySelectorAll("html")[0] - print(tag, tag.text) - img_b64 = tab.screenshot_element("html") +def test_js(tab: AsyncTab): + tab.set_url("https://help.tom.com/") + tag = tab.querySelectorAll(".pr_tit")[0] + assert tag and tag.text + from html import escape + + tab.run_js_snippets("add_tip", f"got the .pr_tit tag[0]: {escape(tag.outerHTML)}") + time.sleep(3) + tab.run_js_snippets("clear_tip") + img_b64 = tab.screenshot_element("#contact", captureBeyondViewport=True) tab.set_html( - f'