Skip to content

Commit

Permalink
Merge pull request #133 from smartcar/add-chrome-driver-support
Browse files Browse the repository at this point in the history
feat(tests): add support for Chrome WebDriver and configurable browser option
  • Loading branch information
aytekin-smartcar authored May 3, 2024
2 parents 6e74f0b + 8885c3c commit 3258a9e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 16 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions tests/auth_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3258a9e

Please sign in to comment.