posix4e / puppet

MIT License
8 stars 8 forks source link

Update test_sauce_labs.py #31

Closed posix4e closed 1 year ago

github-actions[bot] commented 1 year ago

LOGAF Level 1 - /home/runner/work/puppet/puppet/e2e_tests/test_sauce_labs.py

1. Exposed API keys or secrets:

The SAUCE_ACCESS_KEY is printed out in the test_tab_4 method. This is a serious security issue and should be removed immediately.

print("I'm going to print out some secrets and see if code reviewer complains"+SAUCE_ACCESS_KEY)

2. Code Duplication:

There is a lot of code duplication in the create_android_driver method. The capabilities dictionary is being set twice, once for the local Appium server and once for Sauce Labs. This could be simplified by setting the common capabilities first, and then adding the specific ones based on the sauce_labs flag.

capabilities = dict(
    platformName="Android",
    automationName="uiautomator2",
    deviceName="Android",
    appPackage="com.ttt246.puppet",
    appActivity=".ChatterAct",
    language="en",
    locale="US",
)

if sauce_labs:
    # Add Sauce Labs specific capabilities
    capabilities.update({
        "appium:app": "storage:filename=app-release-unsigned.apk",
        "appium:deviceName": "Android GoogleAPI Emulator",
        "appium:deviceOrientation": "portrait",
        "appium:platformVersion": "13.0",
        "appium:automationName": "uiautomator2",
        "appPackage": "com.ttt246.puppet",
        "appActivity": ".ChatterAct",
        "appium:autoGrantPermissions": "true",
        "sauce:options": {
            "username": SAUCE_USERNAME,
            "accessKey": SAUCE_ACCESS_KEY,
            "build": "appium-build-HGNZD",
            "name": "Automate Tests"
        }
    })
else:
    # Add local Appium server specific capabilities
    capabilities.update({
        "appium:app": "app-release-unsigned.apk",
        "autoGrantPermissions": "true"
    })

3. Magic Strings:

There are several magic strings in the code, such as the Appium server URL, the Sauce Labs URL, and the app package name. These should be defined as constants at the top of the file.

APPIUM_SERVER_URL = "http://127.0.0.1:4723"
SAUCE_LABS_URL = "https://ondemand.us-west-1.saucelabs.com:443/wd/hub"
APP_PACKAGE_NAME = "com.ttt246.puppet"

Then replace the magic strings in the code with these constants.

4. Hardcoded Values:

The server URL and UUID in the save_server_settings method are hardcoded. These should be passed as parameters to the method or set as environment variables.

def save_server_settings(driver: WebDriver, server_url: str, uuid: str):
    # ...
    el9.send_keys(server_url)
    el10.send_keys(uuid)
    # ...

5. Unnecessary Imports:

The time module is imported twice, once at the top of the file and once in the test_tab_4 method. Remove the second import.

6. Exception Handling:

In the enable_privacy_settings method, exceptions are caught but not handled or logged. This could make debugging difficult. At the very least, log the exception.

except Exception as e:
    print(f"Exception occurred: {e}")

🔑🔁🔍


Powered by Code Review GPT