add moveing of tabs and groups, multi browser support, auto complite into terminal, extract html and adding testing
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""Tests for dom.* commands (require an http/https active tab)."""
|
||||
import pytest
|
||||
from browser_cli.client import send_command
|
||||
|
||||
|
||||
def test_dom_query_body(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
elements = browser("dom.query", {"selector": "body"})
|
||||
assert isinstance(elements, list)
|
||||
assert len(elements) == 1
|
||||
assert elements[0]["tag"] == "body"
|
||||
|
||||
|
||||
def test_dom_query_multiple(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
# Every HTML page has at least one element
|
||||
elements = browser("dom.query", {"selector": "*"})
|
||||
assert isinstance(elements, list)
|
||||
assert len(elements) > 1
|
||||
|
||||
|
||||
def test_dom_query_no_match(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
elements = browser("dom.query", {"selector": "#zzz_no_such_element_zzz"})
|
||||
assert isinstance(elements, list)
|
||||
assert len(elements) == 0
|
||||
|
||||
|
||||
def test_dom_exists_true(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
result = browser("dom.exists", {"selector": "html"})
|
||||
assert result is True
|
||||
|
||||
|
||||
def test_dom_exists_false(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
result = browser("dom.exists", {"selector": "#zzz_no_such_element_zzz"})
|
||||
assert result is False
|
||||
|
||||
|
||||
def test_dom_text_body(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
texts = browser("dom.text", {"selector": "body"})
|
||||
assert isinstance(texts, list)
|
||||
assert len(texts) > 0
|
||||
assert isinstance(texts[0], str)
|
||||
assert len(texts[0]) > 0
|
||||
|
||||
|
||||
def test_dom_attr_returns_list(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
# Get href of all anchor tags — page may or may not have any
|
||||
hrefs = browser("dom.attr", {"selector": "a", "attr": "href"})
|
||||
assert isinstance(hrefs, list)
|
||||
|
||||
|
||||
def test_dom_attr_html_lang(browser, http_tab):
|
||||
browser("tabs.active", {"tabId": http_tab["id"]})
|
||||
langs = browser("dom.attr", {"selector": "html", "attr": "lang"})
|
||||
assert isinstance(langs, list)
|
||||
# html element exists so we get exactly one entry (may be empty string if no lang attr)
|
||||
assert len(langs) <= 1
|
||||
Reference in New Issue
Block a user