Search code examples
python-3.xseleniumsendkeyswebdriverwaitpython-behave

Secure, automated, login for selenium with python


I am writing test cases using selenium in python for a website, and am having trouble finding the best way to pass a correct login for each scenario. Currently I am using a wait and manually typing in the account information every time:

@given('I wait for input of correct credentials')
    def step_impl(context):
        WebDriverWait(context.driver, 20).until( 
             expected_conditions.visibility_of_elements_located(
                BasePageLocators.SIDEBAR)
        )

Is there a better way without having to send the information in my code? Preferably one that involves no manual input


Solution

  • While this article was written specifically to address how to handle SauceLabs-related creds, there's no reason you can't use the same method.

    You take the credentials and store it outside of your code, e.g. in a Windows Environment variable, some local file, or the like. That way people with access to your repo don't have access to your credentials. It also allows each user to set up their own local credentials so that everyone can use their own credentials without modifying the scripts.