e2e_tests/nextcloud_test.py
2023-07-07 03:38:10 +02:00

90 lines
3.9 KiB
Python

import pytest
from playwright.sync_api import Browser, expect
from conftest import CONFIG, RECORDS, check_for, testuser, setup_context, STATES
# playwright = sync_playwright().start()
# browser = playwright.chromium.launch(headless=False)
""" Delete Nextcloud Account """
@pytest.fixture(scope="session", autouse=True)
def delete_nextcloud_user(browser: Browser):
yield
context = setup_context(browser, f"{STATES}/admin_state.json")
page = context.new_page()
page.goto(CONFIG['domain'])
with page.expect_popup() as nextcloud_info:
page.get_by_role("link", name="Nextcloud").click()
nextcloud = nextcloud_info.value
nextcloud.get_by_role("link", name="Open settings menu").click()
nextcloud.get_by_role("link", name="Users").click()
nextcloud.locator("#app-content div").filter(has_text=testuser["username"]).get_by_role("button", name="Toggle user actions menu").click()
nextcloud.get_by_role("button", name="Delete user").click()
nextcloud.get_by_role("button", name=f"Delete authentik-{testuser['username']}'s account").click()
context.tracing.stop(path=f"{RECORDS}/nextcloud_delete_user.zip")
context.close()
""" Nextcloud Login """
@pytest.fixture(scope="session", autouse=True)
def nc_login(browser: Browser):
context = setup_context(browser, f"{STATES}/user_state.json")
page = context.new_page()
page.goto(CONFIG['domain'])
with page.expect_popup() as nextcloud_info:
link = page.get_by_role("link", name="Nextcloud")
CONFIG['nc_domain'] = link.get_attribute("href")
link.click()
nextcloud = nextcloud_info.value
check_for(nextcloud.get_by_role("link", name="Name"))
if nextcloud.query_selector('.close-icon'):
close_button = nextcloud.get_by_role("button", name="Close modal")
close_button.click()
expect(close_button).to_be_hidden()
nextcloud.wait_for_timeout(2000)
context.storage_state(path=f"{STATES}/nc_user_state.json")
context.tracing.stop(path=f"{RECORDS}/nextcloud_login_user.zip")
context.close()
""" Reuse Nextcloud User Session """
@pytest.fixture
def nc_session(browser: Browser):
context = setup_context(browser, f"{STATES}/nc_user_state.json")
page = context.new_page()
page.goto(CONFIG['nc_domain'])
if page.query_selector('.close-icon'):
page.get_by_role("button", name="Close modal").click()
yield context, page
context.close()
""" Test Nextcloud """
def test_nextcloud(nc_session):
context, page = nc_session
#if page.query_selector('.close-icon'):
# page.get_by_role("button", name="Close modal").click()
if CONFIG.get('default_quota'):
quota = int(page.get_by_role("listitem", name="Storage informations").get_by_role("link").inner_text().split()[3])
assert quota == CONFIG['default_quota']
for app in CONFIG['nc_apps']:
check_for(page.get_by_role("link", name=app))
context.tracing.stop(path=f"{RECORDS}/nextcloud.zip")
""" Test Onlyoffice in Nextcloud """
def test_onlyoffice(nc_session):
context, page = nc_session
#if page.query_selector('.close-icon'):
# page.get_by_role("button", name="Close modal").click()
page.get_by_role("link", name="New file/folder menu").click()
page.get_by_role("link", name="New document").click()
page.locator("#view9-input-file").fill("test.docx")
page.get_by_role("button", name="Submit").click()
outer_frame = page.frame_locator('#onlyofficeFrame')
check_for(outer_frame.locator('body'))
inner_frame = outer_frame.frame_locator('#app > iframe')
check_for(inner_frame.locator('body'))
onlyoffice = page.frame("frameEditor")
check_for(onlyoffice.locator('//*[@id="area_id"]'))
onlyoffice.locator("#btn-goback").click()
page.get_by_role("link", name="Not favorited test .docx Share Actions").get_by_role("link", name="Actions").click()
page.get_by_role("link", name="Delete file").click()
context.tracing.stop(path=f"{RECORDS}/onlyoffice.zip")