Merge branch 'master' into qa

* master:
  tests for dismissal of javascript dialogs (alert, prompt, confirm)
  dismiss alerts from the page being browsed (avoids hanging)
This commit is contained in:
Noah Levitt 2017-01-13 11:46:52 -08:00
commit 87eeaf7888
7 changed files with 83 additions and 2 deletions

View File

@ -202,6 +202,17 @@ class WebsockReceiverThread(threading.Thread):
if self.on_response:
self.on_response(message)
def _javascript_dialog_opening(self, message):
self.logger.info('javascript dialog opened: %s', message)
if message['params']['type'] == 'alert':
accept = True
else:
accept = False
self.websock.send(
json.dumps(dict(
id=0, method='Page.handleJavaScriptDialog',
params={'accept': accept})))
def _handle_message(self, websock, json_message):
message = json.loads(json_message)
if 'method' in message:
@ -223,6 +234,8 @@ class WebsockReceiverThread(threading.Thread):
'%s console.%s %s', self.websock.url,
message['params']['message']['level'],
message['params']['message']['text'])
elif message['method'] == 'Page.javascriptDialogOpening':
self._javascript_dialog_opening(message)
# else:
# self.logger.debug("%s %s", message["method"], json_message)
elif 'result' in message:

View File

@ -32,7 +32,7 @@ def find_package_data(package):
setuptools.setup(
name='brozzler',
version='1.1b9.dev165',
version='1.1b9.dev167',
description='Distributed web crawling with browsers',
url='https://github.com/internetarchive/brozzler',
author='Noah Levitt',

View File

@ -0,0 +1,13 @@
<html>
<head>
<title>a page that pops up an alert</title>
<script>
alert("I'm an alert")
</script>
</head>
<body>
<h1>alert</h1>
<p>this is a page that pops up an alert</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
<html>
<head>
<title>a page that pops up an alert</title>
<script>
confirm("I'm a confirm dialog")
</script>
</head>
<body>
<h1>confirm</h1>
<p>this is a page that pops up a confirm modal dialog</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
<html>
<head>
<title>a page that pops up an print dialog</title>
<script>
print()
</script>
</head>
<body>
<h1>print</h1>
<p>this is a page that pops up a print dialog</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
<html>
<head>
<title>a page that pops up an prompt</title>
<script>
prompt("I'm a prompt")
</script>
</head>
<body>
<h1>prompt</h1>
<p>this is a page that pops up a prompt</p>
</body>
</html>

View File

@ -114,7 +114,6 @@ def test_on_response(httpd):
url = 'http://localhost:%s/site3/page.html' % httpd.server_port
with brozzler.Browser(chrome_exe=chrome_exe) as browser:
browser.browse_page(url, on_response=on_response)
browser.browse_page(url)
assert response_urls[0] == 'http://localhost:%s/site3/page.html' % httpd.server_port
assert response_urls[1] == 'http://localhost:%s/site3/brozzler.svg' % httpd.server_port
assert response_urls[2] == 'http://localhost:%s/favicon.ico' % httpd.server_port
@ -126,3 +125,20 @@ def test_420(httpd):
with pytest.raises(brozzler.ReachedLimit) as excinfo:
browser.browse_page(url)
assert excinfo.value.warcprox_meta == WARCPROX_META_420
def test_js_dialogs(httpd):
chrome_exe = brozzler.suggest_default_chrome_exe()
url = 'http://localhost:%s/site4/alert.html' % httpd.server_port
with brozzler.Browser(chrome_exe=chrome_exe) as browser:
# before commit d2ed6b97a24 these would hang and eventually raise
# brozzler.browser.BrowsingTimeout, which would cause this test to fail
browser.browse_page(
'http://localhost:%s/site4/alert.html' % httpd.server_port)
browser.browse_page(
'http://localhost:%s/site4/confirm.html' % httpd.server_port)
browser.browse_page(
'http://localhost:%s/site4/prompt.html' % httpd.server_port)
# XXX print dialog unresolved
# browser.browse_page(
# 'http://localhost:%s/site4/print.html' % httpd.server_port)