diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7580298c..42beb130 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,12 @@ Please be sure to read the contribution guidelines before making or requesting a #### Requirements: -You will need [geckodriver](https://github.com/mozilla/geckodriver/releases) (and subsequently, Firefox) to run tests +To run tests, you will need the appropriate WebDriver for your chosen browser. This guide assumes you are using either Firefox or Chrome: + +- For Firefox, download [geckodriver](https://github.com/mozilla/geckodriver/releases). +- For Chrome, download [chromedriver](https://chromedriver.chromium.org/downloads). + +Ensure that the chosen driver is in your system's PATH, or you can specify the path directly in your test scripts. The tests make requests to the Smartcar API, so you'll need to create an application on Smartcar and get your client id and client secret. You'll also need to add the testing redirect URI to your application. @@ -56,6 +61,16 @@ pytest -s tests/e2e/test_vehicle.py::test_odometer # Refer to pytest docs for more about pytest! ``` +#### Configuring the Browser for Testing: + +You can specify which browser to use for running the tests by setting the `BROWSER` environment variable. If not set, it defaults to Firefox: + +```bash +export BROWSER='firefox' # Use Firefox +# or +export BROWSER='chrome' # Use Chrome +``` + ## Formatting All code in this repository is formatted using [black](https://github.com/python/black). Please format all contributions diff --git a/tests/auth_helpers.py b/tests/auth_helpers.py index 25e5c9a9..8f4c14d2 100644 --- a/tests/auth_helpers.py +++ b/tests/auth_helpers.py @@ -6,6 +6,8 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from distutils.util import strtobool +from selenium.webdriver.chrome.service import Service as ChromeService +from selenium.webdriver.chrome.options import Options as ChromeOptions import smartcar.helpers as helpers @@ -15,6 +17,7 @@ # Smartcar client environment variables (Required) CLIENT_ID = os.environ["E2E_SMARTCAR_CLIENT_ID"] CLIENT_SECRET = os.environ["E2E_SMARTCAR_CLIENT_SECRET"] +BROWSER = os.environ.get("BROWSER", "firefox") REDIRECT_URI = "https://example.com/auth" # Variables for testing webhooks (Optional): @@ -58,10 +61,23 @@ def get_code_from_url(url): return search_params["code"] +def get_driver(browser_name, headless=False): + if browser_name.lower() == "chrome": + chrome_options = ChromeOptions() + chrome_options.headless = headless + driver = webdriver.Chrome(options=chrome_options) + elif browser_name.lower() == "firefox": + firefox_options = webdriver.FirefoxOptions() + firefox_options.headless = headless + driver = webdriver.Firefox(options=firefox_options) + else: + raise ValueError("Unsupported browser: {}".format(browser_name)) + + return driver + + def run_auth_flow(auth_url, brand="CHEVROLET"): - firefox_options = webdriver.FirefoxOptions() - firefox_options.headless = HEADLESS - driver = webdriver.Firefox(options=firefox_options) + driver = get_driver(BROWSER, headless=True) driver.get(auth_url) # Preamble