Skip to content

Commit

Permalink
OPIK-599 Andrei/tests linting (#881)
Browse files Browse the repository at this point in the history
* basic experiment items tests

* linting

* forgot the rest of the files

* package bases

* fix check again

* linting errors

* one more f-string

* temporary leniency for untyped stuff

* oops

* more fixes

* more

* wrong path

* running into an interactive prompt

* that wasnt working apparently

* linter fixes

* fixed imports

* lint fix

---------

Co-authored-by: Andrei Căutișanu <[email protected]>
  • Loading branch information
AndreiCautisanu and Andrei Căutișanu authored Dec 12, 2024
1 parent 2f81aea commit b7d82d7
Show file tree
Hide file tree
Showing 37 changed files with 977 additions and 683 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/tests_end_to_end_linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: E2E Tests Linter
run-name: "E2E Tests Linter ${{ github.ref_name }} by @${{ github.actor }}"
on:
pull_request:
paths:
- 'tests_end_to_end/**'
push:
branches:
- 'main'
paths:
- 'tests_end_to_end/**'
jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tests_end_to_end
steps:
- uses: actions/checkout@v4
- name: install pre-commit
run: pip install pre-commit
- name: linting
run: pre-commit run --all-files
25 changes: 25 additions & 0 deletions tests_end_to_end/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
files: ^tests_end_to_end
- id: end-of-file-fixer
files: ^tests_end_to_end

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
args: [ --fix, --show-fixes]
files: ^tests_end_to_end
- id: ruff-format
files: ^tests_end_to_end

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
files: ^tests_end_to_end
args: [--config-file, tests_end_to_end/pyproject.toml]
additional_dependencies: ['types-PyYAML']
2 changes: 1 addition & 1 deletion tests_end_to_end/installer_utils/check_backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ do
done

echo "Error: Backend did not respond with 200 OK after $((max_retries * wait_interval)) seconds."
exit 1
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ if [[ $retries -eq $max_retries ]]; then
echo "Containers failed to start"
docker compose ps
exit 1
fi
fi
2 changes: 1 addition & 1 deletion tests_end_to_end/installer_utils/test_app_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from playwright.sync_api import Page, expect


def test_app_loads(page: Page):
page.goto("http://localhost:5173/default/projects")
expect(page.get_by_role("heading", name="Projects")).to_be_visible()

84 changes: 45 additions & 39 deletions tests_end_to_end/page_objects/DatasetItemsPage.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,99 @@
from playwright.sync_api import Page, expect, Locator
from playwright.sync_api import Page


class DatasetItemsPage:
def __init__(self, page: Page):
self.page = page
self.next_page_button_locator = self.page.locator("div:has(> button:nth-of-type(4))").locator('button:nth-of-type(3)')
self.next_page_button_locator = self.page.locator(
"div:has(> button:nth-of-type(4))"
).locator("button:nth-of-type(3)")

def remove_default_columns(self):
self.page.get_by_role('button', name='Columns').click()
created_toggle = self.page.get_by_role('button', name='Created', exact=True).get_by_role('checkbox')
self.page.get_by_role("button", name="Columns").click()
created_toggle = self.page.get_by_role(
"button", name="Created", exact=True
).get_by_role("checkbox")
if created_toggle.is_checked():
created_toggle.click()

last_updated_toggle = self.page.get_by_role('button', name='Last updated').get_by_role('checkbox')

last_updated_toggle = self.page.get_by_role(
"button", name="Last updated"
).get_by_role("checkbox")
if last_updated_toggle.is_checked():
last_updated_toggle.click()

created_by_toggle = self.page.get_by_role('button', name='Created by', exact=True).get_by_role('checkbox')
created_by_toggle = self.page.get_by_role(
"button", name="Created by", exact=True
).get_by_role("checkbox")
if created_by_toggle.is_checked():
created_by_toggle.click()

self.page.keyboard.press('Escape')

self.page.keyboard.press("Escape")

def delete_first_item_on_page_and_return_content(self):
self.remove_default_columns()
keys: list[str] = self.page.locator('th').all_inner_texts()[1:-1]
item={}
keys: list[str] = self.page.locator("th").all_inner_texts()[1:-1]
item = {}

row = self.page.locator('tr').nth(1)
cells = row.locator('td').all()
row = self.page.locator("tr").nth(1)
cells = row.locator("td").all()
for cell_index, cell in enumerate(cells[1:-1]):
content = ''
content = ""
if cell_index == 0:
cell.get_by_role('button').hover()
row.get_by_role('button').nth(1).click()
content = self.page.evaluate('navigator.clipboard.readText()')
cell.get_by_role("button").hover()
row.get_by_role("button").nth(1).click()
content = self.page.evaluate("navigator.clipboard.readText()")
else:
content = cell.text_content()
item[keys[cell_index]] = content

row.get_by_role('button', name='Actions menu').click()
self.page.get_by_role('menuitem', name='Delete').click()
self.page.get_by_role('button', name='Delete dataset item').click()

return item
row.get_by_role("button", name="Actions menu").click()
self.page.get_by_role("menuitem", name="Delete").click()
self.page.get_by_role("button", name="Delete dataset item").click()

return item

def insert_dataset_item(self, item: str):
self.page.get_by_role('button', name='Create dataset item').click()
textbox = self.page.get_by_role('textbox')
self.page.get_by_role("button", name="Create dataset item").click()
textbox = self.page.get_by_role("textbox")
textbox.focus()
self.page.keyboard.press('Meta+A')
self.page.keyboard.press('Backspace')
self.page.keyboard.press("Meta+A")
self.page.keyboard.press("Backspace")
textbox.fill(item)
self.page.get_by_role('button', name='Create dataset item').click()
self.page.get_by_role("button", name="Create dataset item").click()


def get_all_dataset_items_on_current_page(self):
self.remove_default_columns()

keys: list[str] = self.page.locator('th').all_inner_texts()[1:-1]
keys: list[str] = self.page.locator("th").all_inner_texts()[1:-1]
items = []

rows = self.page.locator('tr').all()
rows = self.page.locator("tr").all()
for row_index, row in enumerate(rows[1:]):
item = {}
cells = row.locator('td').all()
cells = row.locator("td").all()
for cell_index, cell in enumerate(cells[1:-1]):
content = ''
content = ""
if cell_index == 0:
cell.get_by_role('button').hover()
row.get_by_role('button').nth(1).click()
content = self.page.evaluate('navigator.clipboard.readText()')
cell.get_by_role("button").hover()
row.get_by_role("button").nth(1).click()
content = self.page.evaluate("navigator.clipboard.readText()")
else:
content = cell.text_content()
item[keys[cell_index]] = content
items.append(item)

return items


def get_all_items_in_dataset(self):
items = []
items.extend(self.get_all_dataset_items_on_current_page())
while self.next_page_button_locator.is_visible() and self.next_page_button_locator.is_enabled():
while (
self.next_page_button_locator.is_visible()
and self.next_page_button_locator.is_enabled()
):
self.next_page_button_locator.click()
self.page.wait_for_timeout(500)
items.extend(self.get_all_dataset_items_on_current_page())

return items


21 changes: 12 additions & 9 deletions tests_end_to_end/page_objects/DatasetsPage.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from playwright.sync_api import Page, expect


class DatasetsPage:
def __init__(self, page: Page):
self.page = page
self.url = '/default/datasets'
self.url = "/default/datasets"

def go_to_page(self):
self.page.goto(self.url)

def create_dataset_by_name(self, dataset_name: str):
self.page.get_by_role('button', name='Create new dataset').first.click()
self.page.get_by_placeholder('Dataset name').fill(dataset_name)
self.page.get_by_role('button', name='Create dataset').click()
self.page.get_by_role("button", name="Create new dataset").first.click()
self.page.get_by_placeholder("Dataset name").fill(dataset_name)
self.page.get_by_role("button", name="Create dataset").click()

def select_database_by_name(self, name):
self.page.get_by_text(name, exact=True).first.click()
Expand All @@ -22,15 +23,17 @@ def search_dataset(self, dataset_name):

def check_dataset_exists_on_page_by_name(self, dataset_name):
expect(self.page.get_by_text(dataset_name).first).to_be_visible()

def check_dataset_not_exists_on_page_by_name(self, dataset_name):
expect(self.page.get_by_text(dataset_name).first).not_to_be_visible()

def delete_dataset_by_name(self, dataset_name):
self.search_dataset(dataset_name)
row = self.page.get_by_role('row').filter(has_text=dataset_name).filter(has=self.page.get_by_role('cell', name=dataset_name, exact=True))
row = (
self.page.get_by_role("row")
.filter(has_text=dataset_name)
.filter(has=self.page.get_by_role("cell", name=dataset_name, exact=True))
)
row.get_by_role("button").click()
self.page.get_by_role("menuitem", name="Delete").click()
self.page.get_by_role("button", name="Delete dataset").click()


43 changes: 22 additions & 21 deletions tests_end_to_end/page_objects/ExperimentItemsPage.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
from playwright.sync_api import Page, expect, Locator
from playwright.sync_api import Page, Locator
import re

class ExperimentItemsPage:

class ExperimentItemsPage:
def __init__(self, page: Page):
self.page = page
self.next_page_button_locator = self.page.locator("div:has(> button:nth-of-type(4))").locator('button:nth-of-type(3)')
self.next_page_button_locator = self.page.locator(
"div:has(> button:nth-of-type(4))"
).locator("button:nth-of-type(3)")

def get_pagination_button(self) -> Locator:
return self.page.get_by_role('button', name='Showing')
return self.page.get_by_role("button", name="Showing")

def get_total_number_of_items_in_experiment(self):
pagination_button_text = self.get_pagination_button().inner_text()
match = re.search(r'of (\d+)', pagination_button_text)
match = re.search(r"of (\d+)", pagination_button_text)
if match:
return int(match.group(1))
else:
return 0

def get_id_of_nth_experiment_item(self, n: int):
row = self.page.locator('tr').nth(n+1)
cell = row.locator('td').first
row = self.page.locator("tr").nth(n + 1)
cell = row.locator("td").first
cell.hover()
cell.get_by_role('button').nth(1).click()
id = self.page.evaluate('navigator.clipboard.readText()')
cell.get_by_role("button").nth(1).click()
id = self.page.evaluate("navigator.clipboard.readText()")
return id



def get_all_item_ids_on_current_page(self):
ids = []
rows = self.page.locator('tr').all()
rows = self.page.locator("tr").all()
for row_index, row in enumerate(rows[2:]):
item = {}
cells = row.locator('td').all()
cell = row.locator('td').first
cell = row.locator("td").first
cell.hover()
cell.get_by_role('button').nth(1).click()
id = self.page.evaluate('navigator.clipboard.readText()')
cell.get_by_role("button").nth(1).click()
id = self.page.evaluate("navigator.clipboard.readText()")
ids.append(id)

return ids


def get_all_item_ids_in_experiment(self):
ids = []
ids.extend(self.get_all_item_ids_on_current_page())
while self.next_page_button_locator.is_visible() and self.next_page_button_locator.is_enabled():
while (
self.next_page_button_locator.is_visible()
and self.next_page_button_locator.is_enabled()
):
self.next_page_button_locator.click()
self.page.wait_for_timeout(500)
ids.extend(self.get_all_dataset_items_on_current_page())

return ids
return ids
19 changes: 11 additions & 8 deletions tests_end_to_end/page_objects/ExperimentsPage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from playwright.sync_api import Page, expect


class ExperimentsPage:
def __init__(self, page: Page):
self.page = page
self.url = '/default/experiments'
self.search_bar = self.page.get_by_test_id('search-input')
self.url = "/default/experiments"
self.search_bar = self.page.get_by_test_id("search-input")

def go_to_page(self):
self.page.goto(self.url)
Expand All @@ -15,18 +16,20 @@ def search_experiment_by_name(self, exp_name: str):

def click_first_experiment_that_matches_name(self, exp_name: str):
self.search_experiment_by_name(exp_name=exp_name)
self.page.get_by_role('link', name=exp_name).first.click()
self.page.get_by_role("link", name=exp_name).first.click()

def check_experiment_exists_by_name(self, exp_name: str):
self.search_experiment_by_name(exp_name)
expect(self.page.get_by_text(exp_name).first).to_be_visible()

def check_experiment_not_exists_by_name(self, exp_name: str):
self.search_experiment_by_name(exp_name)
expect(self.page.get_by_text(exp_name)).not_to_be_visible()

def delete_experiment_by_name(self, exp_name: str):
self.search_experiment_by_name(exp_name)
self.page.get_by_role('row', name=exp_name).first.get_by_role('button', name='Actions menu').click()
self.page.get_by_role('menuitem', name='Delete').click()
self.page.get_by_role('button', name='Delete experiment').click()
self.page.get_by_role("row", name=exp_name).first.get_by_role(
"button", name="Actions menu"
).click()
self.page.get_by_role("menuitem", name="Delete").click()
self.page.get_by_role("button", name="Delete experiment").click()
5 changes: 3 additions & 2 deletions tests_end_to_end/page_objects/IndividualDatasetPage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from playwright.sync_api import Page, expect


class IndividualDatasetPage:
def __init__(self, page: Page):
self.page = page
self.traces_table = page.get_by_role('table')
self.traces_table = page.get_by_role("table")

def check_cell_exists_by_text(self, text):
expect(self.traces_table.get_by_text(text, exact=True)).to_be_visible()
expect(self.traces_table.get_by_text(text, exact=True)).to_be_visible()
Loading

0 comments on commit b7d82d7

Please sign in to comment.