SeleniumBase/seleniumbase/common
Michael Mintz efcdf85178 Update the rate-limiting decorator 2019-09-16 05:07:18 -04:00
..
ReadMe.md Simplify an import statement 2018-10-08 00:40:41 -04:00
__init__.py Fresh Copy 2015-12-04 16:11:53 -05:00
decorators.py Update the rate-limiting decorator 2019-09-16 05:07:18 -04:00
encryption.py flake8 fixes 2018-11-05 00:23:53 -05:00
obfuscate.py Better exception handling. 2018-02-08 18:00:25 -05:00
unobfuscate.py Better handling of Python versions 2019-07-30 02:57:55 -04:00

ReadMe.md

Using methods from the "common" folder.

Part 1: Decorators - (from decorators.py)

Use these Python decorators with your test methods as needed:

  • @retry_on_exception(tries=6, delay=1, backoff=2, max_delay=32)

  • @rate_limited(max_per_second)

Example demonstrating a rate-limited printing functionality:

import unittest
from seleniumbase import decorators


class MyTestClass(unittest.TestCase):

    @decorators.rate_limited(3.5)  # The arg is max calls per second
    def print_item(self, item):
        print(item)

    def test_rate_limited_printing(self):
        print("\nRunning rate-limited print test:")
        for item in range(1, 11):
            self.print_item(item)

Part 2: String/Password Obfuscation, Encryption, and Decryption

Intro:

Often in your tests, you may need to login to a website to perform testing. This generally means storing passwords in plaintext formats. For security reasons, that may not be an optimal solution. For this reason, encryption/obfuscation tools have been built here to help you mask your passwords in your tests. It's not a bulletproof solution, but it can keep anyone looking over your shoulder during test creation from getting your login passwords if they don't have your encryption key, which is stored in a separate file.

Usage:

  • First, set your custom encryption/decryption key in your local clone of settings.py. (If you modify they key later, you'll need to encrypt all your passwords again.)

  • Next, use obfuscate.py to obfuscate/encrypt passwords into coded strings:

python obfuscate.py

Enter password to obfuscate: (CTRL-C to exit)
Password: *********
Verify password:
Password: *********

Here is the obfuscated password:
$^*ENCRYPT=RXlYMSJWTz8HSwM=?&#$

(You can also use unobfuscate.py to encrypt passwords without having them masked while typing them. Or you can use it to decrypt an obfuscated pasword.)

  • Finally, in your tests you can now decrypt obfuscated passwords for use in login methods like this:
from seleniumbase.common import encryption
...
password = encryption.decrypt('$^*ENCRYPT=RXlYMSJWTz8HSwM=?&#$')

(You'll notice that encrypted strings have a common start token and end token. This is to help tell them apart from non-encrypted strings. You can customize these tokens in settings.py. The current default setting is $^*ENCRYPT= for the start token and ?&#$ for the end token.)