diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index fcb13ea..d86b56d 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -1,14 +1,20 @@ name: Run Tests (parallel) -on: [workflow_dispatch] +on: + workflow_dispatch: + pull_request: + types: + - opened + - edited + branches: + - main + - 'releases/**' jobs: test: name: Run tests runs-on: ubuntu-latest - - container: - image: python:3.11.7-alpine3.18 + container: node:20-bookworm strategy: fail-fast: false @@ -18,7 +24,9 @@ jobs: services: selenium: image: selenium/standalone-${{ matrix.browser }}:4.15.0-20231129 - options: --shm-size=2gb + options: --shm-size 2gb + ports: + - 4444:4444 env: SE_NODE_OVERRIDE_MAX_SESSIONS: true SE_NODE_MAX_SESSIONS: 15 @@ -26,10 +34,16 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11.7" - - run: pip install -r requirements-lock.txt - - run: pytest -vv --use-browser remote + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements-lock.txt + + - name: Test with pytest + run: pytest -vv --use-browser remote env: - SELENIUM_HOST: ${{ matrix.browser }} + SELENIUM_BROWSER: ${{ matrix.browser }} \ No newline at end of file diff --git a/README.md b/README.md index 421eadd..cd0ee9f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Automated tests using Python flavor of the Selenium framework. - [Set a default browser to run a specific test](#set-a-default-browser-to-run-a-specific-test) - [Using `pytest` parametrize option to repeat test on different browsers](#using-pytest-parametrize-option-to-repeat-test-on-different-browsers) - [Using containers to run tests](#using-containers-to-run-tests) + - [Custom environment variables](#custom-environment-variables) # How to install @@ -125,4 +126,10 @@ make se-docker-up # starts the docker containers set by containers/compose.yaml make se-docker-run-tests #Running tests for Firefox, Chrome and Edge browsers from docker containers make se-docker-down # terminates the docker containers set by containers/compose.yaml file -``` \ No newline at end of file +``` + +### Custom environment variables + +The following environment variables are used to and often necessary, depending on what and how the tests should be executed: +- `SELENIUM_HOST`: Used to set WHERE to point out the WebDriver's API requests to, when using the `--use-browser` is set to **remote**; (introduced) +- `SELENIUM_BROWSER`: This one refers to what type of browser will be used on the remote test execution. Important to use on GitHub's action workflow (introduced by [#2](https://github.com/thiagojacinto/selenium-with-python-getstarted/issues/2)) \ No newline at end of file diff --git a/tests/pages/BasePageObject.py b/tests/pages/BasePageObject.py index 2aab33d..ad2b117 100644 --- a/tests/pages/BasePageObject.py +++ b/tests/pages/BasePageObject.py @@ -26,8 +26,9 @@ def __init__(self, driver = None): self.driver = webdriver.Firefox(new_driver_options) case "remote": hostname = os.environ.get("SELENIUM_HOST", "selenium") + host_browser = os.environ.get("SELENIUM_BROWSER", hostname) - match hostname.lower(): + match host_browser.lower(): case "chrome": new_driver_options = ChromeOptions() case "firefox":