Skip to content

Commit

Permalink
Merge pull request #3 from thiagojacinto/fix/running-tests-on-gh-action
Browse files Browse the repository at this point in the history
fix: github action tests execution - issue #2
  • Loading branch information
thiagojacinto authored Dec 12, 2023
2 parents 77bf873 + bf1c0c4 commit 836dd52
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,18 +24,26 @@ 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
SE_NODE_SESSION_TIMEOUT: 30

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 }}
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```
```

### 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))
3 changes: 2 additions & 1 deletion tests/pages/BasePageObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 836dd52

Please sign in to comment.