From 78365c9f3576a215ece3792a6a790df8ab1adcfb Mon Sep 17 00:00:00 2001 From: Jake L Date: Tue, 14 Apr 2020 17:19:53 -0400 Subject: [PATCH] Expanding Brozzler's logging in capabilities Some sites don't allow you to login without clicking on a button to open a retracted modal. This update to the login code allows Brozzler to click on all elements that we think are related to opening a login modal. Then, if there isn't a regular form, we will attempt to fill out abnormal form schemes. The test_try_login test has been expanded for the new type of login form we are supporting. --- brozzler/js-templates/try-login.js.j2 | 38 +++++++++++++++++++++++++++ tests/htdocs/site11/form2.html | 25 ++++++++++++++++++ tests/test_brozzling.py | 14 ++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/htdocs/site11/form2.html diff --git a/brozzler/js-templates/try-login.js.j2 b/brozzler/js-templates/try-login.js.j2 index c07a296..fb4ee59 100644 --- a/brozzler/js-templates/try-login.js.j2 +++ b/brozzler/js-templates/try-login.js.j2 @@ -1,6 +1,11 @@ var __brzl_tryLoginState = 'trying'; var __brzl_tryLogin = function() { + for(var x = 0; x < document.querySelectorAll("[class^='login-open']").length; x++){ + button = document.querySelectorAll("[class^='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 +53,39 @@ var __brzl_tryLogin = function() { return; } } + + + if(__brzl_tryLoginState === 'trying'){ + var submit = undefined; + var usernameInput = undefined; + var passwordField = undefined; + + for (var z = 0; z < document.querySelectorAll("[class^='login']").length; z++){ + var input = document.querySelectorAll("[class^='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'; }; diff --git a/tests/htdocs/site11/form2.html b/tests/htdocs/site11/form2.html new file mode 100644 index 0000000..9f63d65 --- /dev/null +++ b/tests/htdocs/site11/form2.html @@ -0,0 +1,25 @@ + + + brozzler login form test 2 + + +
+