Fix HTML class to use async iter and render on bare mode

This commit is contained in:
Ordanis Sanchez
2018-03-21 18:46:57 -04:00
committed by Alessandro Romano
parent 99f9c89766
commit 69bc5dcb20
2 changed files with 49 additions and 2 deletions
+46
View File
@@ -236,6 +236,29 @@ def test_bare_render():
assert 'https://httpbin.org' in html.links
@pytest.mark.render
@pytest.mark.asyncio
async def test_bare_arender():
doc = """<a href='https://httpbin.org'>"""
html = HTML(html=doc, async_=True)
script = """
() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio,
}
}
"""
val = await html.arender(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
await html.browser.close()
@pytest.mark.render
def test_bare_js_eval():
doc = """
@@ -257,6 +280,29 @@ def test_bare_js_eval():
assert html.find('#replace', first=True).text == 'yolo'
@pytest.mark.render
@pytest.mark.asyncio
async def test_bare_js_async_eval():
doc = """
<!DOCTYPE html>
<html>
<body>
<div id="replace">This gets replaced</div>
<script type="text/javascript">
document.getElementById("replace").innerHTML = "yolo";
</script>
</body>
</html>
"""
html = HTML(html=doc, async_=True)
await html.arender()
assert html.find('#replace', first=True).text == 'yolo'
await html.browser.close()
@pytest.mark.ok
def test_browser_session():
""" Test browser instaces is created and properly close when session is closed.