Skip to content

Commit 836dd52

Browse files
Merge pull request #3 from thiagojacinto/fix/running-tests-on-gh-action
fix: github action tests execution - issue #2
2 parents 77bf873 + bf1c0c4 commit 836dd52

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

.github/workflows/run-tests.yaml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
name: Run Tests (parallel)
22

3-
on: [workflow_dispatch]
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types:
7+
- opened
8+
- edited
9+
branches:
10+
- main
11+
- 'releases/**'
412

513
jobs:
614
test:
715
name: Run tests
816
runs-on: ubuntu-latest
9-
10-
container:
11-
image: python:3.11.7-alpine3.18
17+
container: node:20-bookworm
1218

1319
strategy:
1420
fail-fast: false
@@ -18,18 +24,26 @@ jobs:
1824
services:
1925
selenium:
2026
image: selenium/standalone-${{ matrix.browser }}:4.15.0-20231129
21-
options: --shm-size=2gb
27+
options: --shm-size 2gb
28+
ports:
29+
- 4444:4444
2230
env:
2331
SE_NODE_OVERRIDE_MAX_SESSIONS: true
2432
SE_NODE_MAX_SESSIONS: 15
2533
SE_NODE_SESSION_TIMEOUT: 30
2634

2735
steps:
2836
- uses: actions/checkout@v4
29-
- uses: actions/setup-python@v4
37+
- uses: actions/setup-python@v5
3038
with:
31-
python-version: "3.11.7"
32-
- run: pip install -r requirements-lock.txt
33-
- run: pytest -vv --use-browser remote
39+
python-version: '3.11'
40+
41+
- name: Install dependencies
42+
run: |
43+
python -m pip install --upgrade pip
44+
python -m pip install -r requirements-lock.txt
45+
46+
- name: Test with pytest
47+
run: pytest -vv --use-browser remote
3448
env:
35-
SELENIUM_HOST: ${{ matrix.browser }}
49+
SELENIUM_BROWSER: ${{ matrix.browser }}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Automated tests using Python flavor of the Selenium framework.
1212
- [Set a default browser to run a specific test](#set-a-default-browser-to-run-a-specific-test)
1313
- [Using `pytest` parametrize option to repeat test on different browsers](#using-pytest-parametrize-option-to-repeat-test-on-different-browsers)
1414
- [Using containers to run tests](#using-containers-to-run-tests)
15+
- [Custom environment variables](#custom-environment-variables)
1516

1617

1718
# How to install
@@ -125,4 +126,10 @@ make se-docker-up # starts the docker containers set by containers/compose.yaml
125126
make se-docker-run-tests #Running tests for Firefox, Chrome and Edge browsers from docker containers
126127

127128
make se-docker-down # terminates the docker containers set by containers/compose.yaml file
128-
```
129+
```
130+
131+
### Custom environment variables
132+
133+
The following environment variables are used to and often necessary, depending on what and how the tests should be executed:
134+
- `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)
135+
- `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))

tests/pages/BasePageObject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def __init__(self, driver = None):
2626
self.driver = webdriver.Firefox(new_driver_options)
2727
case "remote":
2828
hostname = os.environ.get("SELENIUM_HOST", "selenium")
29+
host_browser = os.environ.get("SELENIUM_BROWSER", hostname)
2930

30-
match hostname.lower():
31+
match host_browser.lower():
3132
case "chrome":
3233
new_driver_options = ChromeOptions()
3334
case "firefox":

0 commit comments

Comments
 (0)