Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI fixes and improvements #331

Merged
merged 24 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions .github/workflows/di.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
matrix:
tag: [latest]
browser: [Chrome, Firefox]
python-version: ['3.8', '3.10']
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
firefox: ['96.0']
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
fail-fast: false

runs-on: ubuntu-latest
Expand All @@ -28,21 +26,18 @@ jobs:
- name: Check out app
uses: actions/checkout@v2

- name: Cache Python dependencies
uses: actions/cache@v1
- name: Set up Python
uses: actions/setup-python@v4
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-tests-${{ hashFiles('**/setup.json') }}
restore-keys: pip-${{ matrix.python-version }}-tests

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: '3.10'
cache: pip
cache-dependency-path: |
**/setup.cfg
**/pyproject.toml
**/requirements*.txt

- name: Install dependencies for test
run: |
pip install -U -r requirements_test.txt
run: pip install -U -r requirements_test.txt

- name: Set jupyter token env
run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV
Expand All @@ -52,7 +47,7 @@ jobs:
- name: Install Firefox
uses: browser-actions/setup-firefox@latest
with:
firefox-version: ${{ matrix.firefox }}
firefox-version: latest
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
if: matrix.browser == 'Firefox'

- name: Install geckodriver
Expand All @@ -65,3 +60,11 @@ jobs:
run: pytest --driver ${{ matrix.browser }}
env:
TAG: ${{ matrix.tag }}

- name: Upload screenshots as artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: Screenshots-${{ matrix.tag }}-${{ matrix.browser }}
path: ~/screenshots/
if-no-files-found: error
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dev =
bumpver==2022.1119
pre-commit==2.11.1
test =
requirements-test.txt
file:

[options.package_data]
aiidalab_qe.parameters = qeapp.yaml
Expand All @@ -51,9 +51,9 @@ categories =

[flake8]
ignore =
E501 # Line length handled by black.
W503 # Line break before binary operator, preferred formatting for black.
E203 # Whitespace before ':', preferred formatting for black.
E501
W503
E203

[bumpver]
current_version = "v22.12.0"
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from urllib.parse import urljoin

import pytest
Expand Down Expand Up @@ -62,6 +63,13 @@ def _selenium_driver(nb_path, wait_time=5.0):
return _selenium_driver


@pytest.fixture(scope="session")
def screenshot_dir():
sdir = Path.joinpath(Path.home(), "screenshots")
os.mkdir(sdir)
return sdir


@pytest.fixture
def firefox_options(firefox_options):
firefox_options.add_argument("--headless")
Expand Down
16 changes: 11 additions & 5 deletions tests/test_qe_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import requests
from selenium.webdriver.common.by import By

Expand All @@ -8,21 +10,25 @@ def test_notebook_service_available(notebook_service):
assert response.status_code == 200


def test_qe_app_take_screenshot(selenium_driver):
def test_qe_app_take_screenshot(selenium_driver, screenshot_dir):
driver = selenium_driver("qe.ipynb", wait_time=30.0)
driver.set_window_size(1920, 985)
driver.get_screenshot_as_file("screenshots/qe-app.png")
driver.get_screenshot_as_file(str(Path.joinpath(screenshot_dir, "qe-app.png")))


def test_qe_app_select_silicon(selenium_driver):
def test_qe_app_select_silicon(selenium_driver, screenshot_dir):
driver = selenium_driver("qe.ipynb", wait_time=30.0)
driver.set_window_size(1920, 985)
driver.find_element(
By.XPATH, "//*[text()='From Examples']"
).click() # click `From Examples` tab for input structure
driver.find_element(By.XPATH, "//option[@value='Diamond']").click()
driver.get_screenshot_as_file("screenshots/qe-app-select-diamond-selected.png")
driver.get_screenshot_as_file(
str(Path.joinpath(screenshot_dir, "qe-app-select-diamond-selected.png"))
)
confirm_button = driver.find_element(By.XPATH, "//button[text()='Confirm']")
confirm_button.location_once_scrolled_into_view # scroll into view
confirm_button.click()
driver.get_screenshot_as_file("screenshots/qe-app-select-diamond-confirmed.png")
driver.get_screenshot_as_file(
str(Path.joinpath(screenshot_dir, "qe-app-select-diamond-confirmed.png"))
)