mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-04-20 23:56:34 -04:00
commit
ce2fe4754f
@ -1,6 +1,12 @@
|
||||
var __brzl_tryLoginState = 'trying';
|
||||
|
||||
var __brzl_tryLogin = function() {
|
||||
var login_open = document.querySelectorAll("[class^='login-open']");
|
||||
for(var x = 0; x < login_open.length; x++){
|
||||
button = login_open[x];
|
||||
button.click();
|
||||
}
|
||||
|
||||
for (var i = 0; i < document.forms.length; i++) {
|
||||
var form = document.forms[i];
|
||||
if (form.method != 'post') {
|
||||
@ -48,6 +54,38 @@ var __brzl_tryLogin = function() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(__brzl_tryLoginState === 'trying'){
|
||||
var submit = undefined;
|
||||
var usernameInput = undefined;
|
||||
var passwordField = undefined;
|
||||
var login = document.querySelectorAll("[class^='login']");
|
||||
|
||||
for (var z = 0; z < login.length; z++){
|
||||
var input = login[z];
|
||||
|
||||
if (input.type === "text" || input.type == "email") {
|
||||
usernameField = input;
|
||||
} else if (input.type === "password") {
|
||||
passwordField = input;
|
||||
} else if(input.onclick != null) {
|
||||
submit = input;
|
||||
} else if (input.type == "textarea") {
|
||||
usernameField = undefined;
|
||||
passwordField = undefined;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (submit && usernameField && passwordField){
|
||||
usernameField.value = {{username|json}};
|
||||
passwordField.value = {{password|json}};
|
||||
submit.click();
|
||||
__brzl_tryLoginState = 'maybe-submitted-form';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
__brzl_tryLoginState = 'login-form-not-found';
|
||||
};
|
||||
|
||||
|
4
setup.py
4
setup.py
@ -2,7 +2,7 @@
|
||||
'''
|
||||
setup.py - brozzler setup script
|
||||
|
||||
Copyright (C) 2014-2019 Internet Archive
|
||||
Copyright (C) 2014-2020 Internet Archive
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -32,7 +32,7 @@ def find_package_data(package):
|
||||
|
||||
setuptools.setup(
|
||||
name='brozzler',
|
||||
version='1.5.19',
|
||||
version='1.5.20',
|
||||
description='Distributed web crawling with browsers',
|
||||
url='https://github.com/internetarchive/brozzler',
|
||||
author='Noah Levitt',
|
||||
|
25
tests/htdocs/site11/form2.html
Normal file
25
tests/htdocs/site11/form2.html
Normal file
@ -0,0 +1,25 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>brozzler login form test 2</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<a class="login-open-bt" onclick="document.getElementsByClassName('login-box')[0].style = '';">Sign In</li>
|
||||
<div class="login-box" style="display: none;">
|
||||
<div class="login-main">
|
||||
<ul class="login-list">
|
||||
<li>
|
||||
<input type="text" class="login-ipt" placeholder="Email" id="loginEmail">
|
||||
</li>
|
||||
<li>
|
||||
<input type="password" class="login-ipt" placeholder="Password" id="loginPsw">
|
||||
</li>
|
||||
<li>
|
||||
<div class="login-bt" onclick="window.location.href = '/login-action';">Sign In</div>
|
||||
</li>
|
||||
<br>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -80,6 +80,8 @@ def httpd(request):
|
||||
self.send_header('Content-Length', len(payload))
|
||||
self.end_headers()
|
||||
self.wfile.write(payload)
|
||||
else:
|
||||
super().do_POST()
|
||||
|
||||
|
||||
# SimpleHTTPRequestHandler always uses CWD so we have to chdir
|
||||
@ -265,6 +267,7 @@ def test_try_login(httpd):
|
||||
response_urls.append(msg['params']['response']['url'])
|
||||
chrome_exe = brozzler.suggest_default_chrome_exe()
|
||||
form_url = 'http://localhost:%s/site11/form1.html' % httpd.server_port
|
||||
form_url_other = 'http://localhost:%s/site11/form2.html' % httpd.server_port
|
||||
favicon_url = 'http://localhost:%s/favicon.ico' % httpd.server_port
|
||||
login_url = 'http://localhost:%s/login-action' % httpd.server_port
|
||||
# When username and password are defined and initial page has login form,
|
||||
@ -280,6 +283,19 @@ def test_try_login(httpd):
|
||||
assert response_urls[2] == login_url
|
||||
assert response_urls[3] == form_url
|
||||
|
||||
# We are now supporting a different type of form, we'll test that here.
|
||||
response_urls = []
|
||||
username = 'user1'
|
||||
password = 'pass1'
|
||||
with brozzler.Browser(chrome_exe=chrome_exe) as browser:
|
||||
browser.browse_page(form_url_other, username=username, password=password,
|
||||
on_response=on_response)
|
||||
assert len(response_urls) == 4
|
||||
assert response_urls[0] == form_url_other
|
||||
assert response_urls[1] == favicon_url
|
||||
assert response_urls[2] == login_url
|
||||
assert response_urls[3] == form_url_other
|
||||
|
||||
# When username and password are not defined, just load the initial page.
|
||||
response_urls = []
|
||||
with brozzler.Browser(chrome_exe=chrome_exe) as browser:
|
||||
|
Loading…
x
Reference in New Issue
Block a user