Skip to content

Commit 5d99e5c

Browse files
committed
Add ability to handle time-based Google Authenticator logins
1 parent 0e76242 commit 5d99e5c

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

help_docs/features_list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Uses a [global config file](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) for configuring SeleniumBase to your specific needs.
1212
* Backwards-compatible with [WebDriver](http://www.seleniumhq.org/projects/webdriver/). (Use ``self.driver`` anywhere.)
1313
* Can run tests through a proxy server. (Use ``--proxy=IP_ADDRESS:PORT``)
14+
* Can handle Google Authenticator logins by using the [Python one-time password library](https://pyotp.readthedocs.io/en/latest/).
1415
* Includes a hybrid-automation solution called **[MasterQA](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/masterqa/ReadMe.md)** to speed up manual testing.
1516
* Includes integrations with [MySQL](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/core/testcase_manager.py), [Selenium Grid](https://github.com/seleniumbase/SeleniumBase/tree/master/seleniumbase/utilities/selenium_grid), [Google Cloud](https://github.com/seleniumbase/SeleniumBase/tree/master/integrations/google_cloud/ReadMe.md), [Amazon S3](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/s3_logging_plugin.py), and [NodeJS](https://github.com/seleniumbase/SeleniumBase/tree/master/integrations/node_js).
1617
* Includes a [tool to convert Selenium IDE recordings](https://github.com/seleniumbase/SeleniumBase/tree/master/seleniumbase/utilities/selenium_ide) into clean, robust SeleniumBase scripts.

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ self.is_downloaded_file_present(file)
162162

163163
self.assert_downloaded_file(file)
164164

165+
self.get_google_auth_password(totp_key=None)
166+
165167
self.convert_xpath_to_css(xpath)
166168

167169
self.convert_to_css_selector(selector, by)

seleniumbase/config/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@
8888

8989

9090
# #####>>>>>----- RECOMMENDED SETTINGS -----<<<<<#####
91-
# ##### (For database reporting, saving test logs, and password encryption)
91+
# ##### (For multi-factor auth, DB/cloud logging, and password encryption)
92+
93+
# Google Authenticator
94+
# (For 2-factor authentication using a time-based one-time password algorithm)
95+
# (See https://github.com/pyotp/pyotp and https://pypi.org/project/pyotp/ )
96+
# (Also works with Authy and other compatible apps.)
97+
TOTP_KEY = "base32secretABCD"
98+
9299

93100
# MySQL DB Credentials
94101
# (For saving data from tests)

seleniumbase/fixtures/base_case.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,18 @@ def assert_downloaded_file(self, file):
18611861
""" Asserts that the file exists in the Downloads Folder. """
18621862
assert os.path.exists(self.get_path_of_downloaded_file(file))
18631863

1864+
def get_google_auth_password(self, totp_key=None):
1865+
""" Returns a time-based one-time password based on the
1866+
Google Authenticator password algorithm. Works with Authy.
1867+
If "totp_key" is not specified, will default to using
1868+
the one provided in seleniumbase/config/settings.py
1869+
(See https://pyotp.readthedocs.io/en/latest/ for details.) """
1870+
import pyotp
1871+
if not totp_key:
1872+
totp_key = settings.TOTP_KEY
1873+
totp = pyotp.TOTP(totp_key)
1874+
return str(totp.now())
1875+
18641876
def convert_xpath_to_css(self, xpath):
18651877
return xpath_to_css.convert_xpath_to_css(xpath)
18661878

0 commit comments

Comments
 (0)