diff --git a/tests/test_requests_html.py b/tests/test_requests_html.py index 5780bde..dbf02d8 100644 --- a/tests/test_requests_html.py +++ b/tests/test_requests_html.py @@ -44,8 +44,8 @@ def test_links(): r = get() about = r.html.find('#about', first=True) - len(about.links) == 6 - len(about.absolute_links) == 6 + assert len(about.links) == 6 + assert len(about.absolute_links) == 6 def test_search(): @@ -79,5 +79,44 @@ def test_anchor_links(): assert '#site-map' in r.html.links +def test_render(): + r = get() + script = """ + () => { + return { + width: document.documentElement.clientWidth, + height: document.documentElement.clientHeight, + deviceScaleFactor: window.devicePixelRatio, + } + } + """ + val = r.html.render(script=script) + for value in ('width', 'height', 'deviceScaleFactor'): + assert value in val + + about = r.html.find('#about', first=True) + assert len(about.links) == 6 + + +def test_bare_render(): + doc = """""" + html = HTML(html=doc) + script = """ + () => { + return { + width: document.documentElement.clientWidth, + height: document.documentElement.clientHeight, + deviceScaleFactor: window.devicePixelRatio, + } + } + """ + val = html.render(script=script, reload=False) + for value in ('width', 'height', 'deviceScaleFactor'): + assert value in val + + assert html.find('html') + assert 'https://httpbin.org' in html.links + + if __name__ == '__main__': test_xpath()