Skip to content

Commit

Permalink
tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
l0uden committed Dec 13, 2024
1 parent ea7ef47 commit 2ffdbe6
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ runs:
- name: Copy failed screenshots
shell: bash
run: |
mkdir /home/runner/work/vizro/vizro/vizro-core/failed_screenshots/
cd /home/runner/work/vizro/vizro/vizro-core/
mkdir ${{ env.PROJECT_PATH }}failed_screenshots/
cd ${{ env.PROJECT_PATH }}
cp *.png failed_screenshots
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: Failed screenshots
path: |
/home/runner/work/vizro/vizro/vizro-core/failed_screenshots/*.png
${{ env.PROJECT_PATH }}failed_screenshots/*.png
- name: Send custom JSON data to Slack
id: slack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ jobs:
env:
TESTS_NAME: Vizro e2e component library tests
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
PROJECT_PATH: /home/runner/work/vizro/vizro/vizro-core/
66 changes: 66 additions & 0 deletions .github/workflows/test-e2e-vizro-ai-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: e2e tests for VizroAI UI

defaults:
run:
working-directory: vizro-ai

on:
push:
branches: [main]
pull_request:
branches:
- main
paths:
- "vizro-ai/**"
- "!vizro-ai/docs/**"

env:
PYTHONUNBUFFERED: 1
FORCE_COLOR: 1
PYTHON_VERSION: "3.12"

jobs:
test-e2e-vizro-ai-ui-fork:
if: ${{ github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Passed fork step
run: echo "Success!"

test-e2e-vizro-ai-ui:
if: ${{ ! github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Hatch
run: pip install hatch

- name: Show dependency tree
run: hatch run pip tree

- name: Run e2e VizroAI UI tests
run: |
hatch run vizro-ai-ui
tests/test_utils/wait-for-it.sh 127.0.0.1:8050 -t 30
hatch run test-e2e-vizro-ai-ui
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }}

- name: Create artifacts and slack notifications
if: failure()
uses: ./.github/actions/failed-artifacts-and-slack-notifications
env:
TESTS_NAME: e2e VizroAI UI tests
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
PROJECT_PATH: /home/runner/work/vizro/vizro/vizro-ai/
87 changes: 0 additions & 87 deletions .github/workflows/test-vizro-ai-ui.yml

This file was deleted.

5 changes: 1 addition & 4 deletions vizro-ai/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test-unit-coverage = [
"- coverage combine",
"coverage report"
]
test-vizro-ai-ui = "pytest -vs --reruns 1 tests/vizro_ai_ui --headless {args}"
test-e2e-vizro-ai-ui = "pytest -vs --reruns 1 tests/e2e/test_vizro_ai_ui.py --headless {args}"
vizro-ai-ui = "python examples/dashboard_ui/app.py &"

[envs.docs]
Expand All @@ -83,8 +83,5 @@ serve = "mkdocs serve --open"
extra-dependencies = ["pydantic==1.10.16"]
python = "3.9"

[envs.tests]
python = "3.12"

[version]
path = "src/vizro_ai/__init__.py"
2 changes: 2 additions & 0 deletions vizro-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ filterwarnings = [
# Ignore warning for Pydantic v1 API and Python 3.13:
"ignore:Failing to pass a value to the 'type_params' parameter of 'typing.ForwardRef._evaluate' is deprecated:DeprecationWarning"
]
norecursedirs = ["tests/tests_utils"]
pythonpath = ["tests/tests_utils"]

[tool.ruff]
extend = "../pyproject.toml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from tests.helpers.checkers import browser_console_warnings_checker
from e2e_asserts import browser_console_warnings_checker


@pytest.fixture()
Expand Down Expand Up @@ -41,11 +41,10 @@ def test_failed_check(request):
yield
if request.node.rep_setup.failed:
return "setting up a test failed!", request.node.nodeid
elif request.node.rep_setup.passed:
if request.node.rep_call.failed:
driver = request.node.funcargs["chromedriver"]
take_screenshot(driver, request.node.nodeid)
return "executing test failed", request.node.nodeid
elif request.node.rep_setup.passed and request.node.rep_call.failed:
driver = request.node.funcargs["chromedriver"]
take_screenshot(driver, request.node.nodeid)
return "executing test failed", request.node.nodeid


def take_screenshot(driver, nodeid):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from selenium.common import InvalidSelectorException, TimeoutException
from tests.helpers.common import (
from e2e_waiters import (
wait_for,
webdriver_click_waiter,
webdriver_waiter,
Expand All @@ -11,8 +11,8 @@


@pytest.mark.filterwarnings("ignore:HTTPResponse.getheader():DeprecationWarning")
@pytest.mark.filterwarnings("ignore::pytest.PytestUnhandledThreadExceptionWarning")
@pytest.mark.filterwarnings("ignore:unclosed file:ResourceWarning")
# @pytest.mark.filterwarnings("ignore::pytest.PytestUnhandledThreadExceptionWarning")
# @pytest.mark.filterwarnings("ignore:unclosed file:ResourceWarning")
@pytest.mark.parametrize(
"chromedriver",
[({"port": 8050})],
Expand All @@ -30,11 +30,11 @@ def test_chart_ui(chromedriver):

# upload file
file_input = webdriver_waiter_css(chromedriver, 'input[type="file"]')
file_input.send_keys(os.path.abspath("tests/vizro_ai_ui/genre_popularity_by_country.csv"))
webdriver_click_waiter(chromedriver, '//*[@id="data-upload-id"]')
file_input.send_keys(os.path.abspath("tests/tests_utils/genre_popularity_by_country.csv"))
webdriver_click_waiter(chromedriver, '//*[@id="data-upload"]')

# enter prompt
prompt = webdriver_waiter(chromedriver, '//*[@id="text-area-id"]')
prompt = webdriver_waiter(chromedriver, '//*[@id="text-area"]')
prompt.send_keys("Create bar graph by genre")

# choose gpt version
Expand All @@ -43,7 +43,7 @@ def test_chart_ui(chromedriver):
webdriver_click_waiter(chromedriver, '//*/div[text()="gpt-4o-mini"]')

# click run VizroAI
webdriver_click_waiter(chromedriver, '//*[@id="trigger-button-id"]')
webdriver_click_waiter(chromedriver, '//*[@id="trigger-button"]')

# check result
def _text_waiter():
Expand Down
Empty file removed vizro-ai/tests/helpers/__init__.py
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hamcrest import any_of, assert_that, contains_string
from tests.helpers.constants import (
from e2e_constants import (
INVALID_PROP_ERROR,
REACT_NOT_RECOGNIZE_ERROR,
REACT_RENDERING_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
WILLRECEIVEPROPS_RENAMED_WARNING = "componentWillReceiveProps has been renamed"
READPIXELS_WARNING = "GPU stall due to ReadPixels"
WEBGL_WARNING = "WebGL" # https://issues.chromium.org/issues/40277080

TIMEOUT = 30
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from e2e_constants import TIMEOUT


def wait_for(condition_function, *args):
Expand All @@ -20,20 +21,20 @@ def wait_for(condition_function, *args):


def webdriver_click_waiter(browserdriver, xpath):
WebDriverWait(browserdriver, 10, ignored_exceptions=StaleElementReferenceException).until(
WebDriverWait(browserdriver, TIMEOUT, ignored_exceptions=StaleElementReferenceException).until(
expected_conditions.element_to_be_clickable((By.XPATH, xpath))
).click()


def webdriver_waiter(browserdriver, xpath):
elem = WebDriverWait(browserdriver, 10, ignored_exceptions=StaleElementReferenceException).until(
elem = WebDriverWait(browserdriver, TIMEOUT, ignored_exceptions=StaleElementReferenceException).until(
expected_conditions.presence_of_element_located((By.XPATH, xpath))
)
return elem


def webdriver_waiter_css(browserdriver, xpath):
elem = WebDriverWait(browserdriver, 30, ignored_exceptions=StaleElementReferenceException).until(
elem = WebDriverWait(browserdriver, TIMEOUT, ignored_exceptions=StaleElementReferenceException).until(
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, xpath))
)
return elem
File renamed without changes.
Empty file.

0 comments on commit 2ffdbe6

Please sign in to comment.