2023-06-15 12:41:39 +02:00
|
|
|
import random
|
|
|
|
import string
|
2023-06-16 17:14:22 +02:00
|
|
|
from time import time_ns
|
2023-06-09 10:43:34 +02:00
|
|
|
|
2023-06-15 12:41:39 +02:00
|
|
|
from playwright.sync_api import Playwright, sync_playwright, expect
|
|
|
|
|
2023-06-16 17:14:22 +02:00
|
|
|
def log_note(message: str) -> None:
|
2023-06-16 17:23:52 +02:00
|
|
|
timestamp = str(time_ns())[:16]
|
2023-06-16 17:14:22 +02:00
|
|
|
print(f"{timestamp} {message}")
|
2023-06-15 12:41:39 +02:00
|
|
|
|
|
|
|
def get_random_text() -> str:
|
|
|
|
size_in_bytes = 20 * 1024
|
|
|
|
characters = string.ascii_letters + string.digits
|
|
|
|
return ''.join(random.choice(characters) for _ in range(size_in_bytes))
|
|
|
|
|
|
|
|
def send_message(sender, message):
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Sending message")
|
2023-06-15 12:41:39 +02:00
|
|
|
sender.get_by_role("textbox", name="Write message, @ to mention someone …").click()
|
|
|
|
sender.get_by_role("textbox", name="Write message, @ to mention someone …").fill(message)
|
|
|
|
sender.get_by_role("textbox", name="Write message, @ to mention someone …").press("Enter")
|
2023-06-09 10:43:34 +02:00
|
|
|
|
|
|
|
def create_conversation(playwright: Playwright) -> str:
|
2023-06-12 12:22:13 +02:00
|
|
|
headless = True
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Launch browser")
|
2023-06-12 12:22:13 +02:00
|
|
|
browser = playwright.chromium.launch(headless=headless)
|
2023-06-09 10:43:34 +02:00
|
|
|
context = browser.new_context()
|
|
|
|
page = context.new_page()
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Login as admin")
|
2023-06-09 11:49:51 +02:00
|
|
|
page.goto("http://nc/")
|
2023-06-09 10:43:34 +02:00
|
|
|
page.get_by_label("Account name or email").click()
|
|
|
|
page.get_by_label("Account name or email").fill("Crash")
|
|
|
|
page.get_by_label("Account name or email").press("Tab")
|
|
|
|
page.get_by_label("Password", exact=True).fill("Override")
|
|
|
|
page.get_by_role("button", name="Log in").click()
|
2023-06-09 14:41:11 +02:00
|
|
|
|
|
|
|
# Wait for the modal to load. As it seems you can't close it while it is showing the opening animation.
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Close first-time run popup")
|
2023-06-09 14:41:11 +02:00
|
|
|
page.get_by_role("button", name="Close modal").click(timeout=15_000)
|
|
|
|
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Open Talk app")
|
2023-06-09 10:43:34 +02:00
|
|
|
page.get_by_role("link", name="Talk", exact=True).click()
|
2023-06-09 15:05:32 +02:00
|
|
|
page.wait_for_url("**/apps/spreed/")
|
2023-06-09 16:59:12 +02:00
|
|
|
|
|
|
|
# Headless browsers trigger a warning in Nextcloud, however they actually work fine
|
2023-06-12 12:22:13 +02:00
|
|
|
if headless:
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Close headless warning")
|
2023-06-12 12:22:13 +02:00
|
|
|
page.wait_for_selector('.toast-close')
|
|
|
|
page.click('.toast-close')
|
2023-06-09 16:59:12 +02:00
|
|
|
|
2023-06-12 12:22:13 +02:00
|
|
|
page.wait_for_selector('.toast-close')
|
|
|
|
page.click('.toast-close')
|
2023-06-09 16:59:12 +02:00
|
|
|
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Create conversation")
|
2023-06-09 10:43:34 +02:00
|
|
|
page.get_by_role("button", name="Create a new group conversation").click()
|
|
|
|
page.get_by_placeholder("Conversation name").fill("Random talk")
|
|
|
|
page.locator("label").filter(has_text="Allow guests to join via link").locator("svg").click()
|
|
|
|
page.get_by_role("button", name="Create conversation").click()
|
|
|
|
page.get_by_role("button", name="Copy conversation link").click()
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Close browser")
|
2023-06-09 10:43:34 +02:00
|
|
|
|
|
|
|
# ---------------------
|
2023-06-15 15:13:23 +02:00
|
|
|
page.close()
|
2023-06-09 10:43:34 +02:00
|
|
|
context.close()
|
|
|
|
browser.close()
|
|
|
|
|
|
|
|
return page.url
|
|
|
|
|
|
|
|
def talk(playwright: Playwright, url: str) -> None:
|
2023-06-12 12:22:13 +02:00
|
|
|
headless = True
|
2023-06-15 12:41:39 +02:00
|
|
|
action_delay_ms = 300
|
|
|
|
browser_count = 5
|
2023-06-09 16:59:12 +02:00
|
|
|
|
2023-06-15 12:41:39 +02:00
|
|
|
# Launch browsers
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note(f"Launching {browser_count} browsers")
|
2023-06-15 12:41:39 +02:00
|
|
|
browsers = [playwright.chromium.launch(headless=headless, slow_mo=action_delay_ms) for _ in range(browser_count)]
|
|
|
|
contexts = [browser.new_context() for browser in browsers]
|
|
|
|
pages = [context.new_page() for context in contexts]
|
2023-06-09 16:59:12 +02:00
|
|
|
|
2023-06-15 12:41:39 +02:00
|
|
|
# Go to URL for all users
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Navigating to Talk conversation")
|
2023-06-15 12:41:39 +02:00
|
|
|
for page in pages:
|
|
|
|
page.goto(url)
|
2023-06-09 16:59:12 +02:00
|
|
|
|
2023-06-15 12:41:39 +02:00
|
|
|
# Close toast messages for headless browsers
|
|
|
|
if headless:
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Close headless warning")
|
2023-06-15 12:41:39 +02:00
|
|
|
for page in pages:
|
|
|
|
page.wait_for_selector('.toast-close').click()
|
|
|
|
|
|
|
|
# Perform actions for all users
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Set guest usernames")
|
2023-06-15 12:41:39 +02:00
|
|
|
for page in pages:
|
|
|
|
page.get_by_role("button", name="Edit").click()
|
|
|
|
page.get_by_placeholder("Guest").fill(f"Dude#{pages.index(page) + 1}")
|
|
|
|
page.get_by_role("button", name="Save name").click()
|
|
|
|
|
|
|
|
# Send first message and check for visibility
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Send the first validation message")
|
2023-06-15 12:41:39 +02:00
|
|
|
sender = pages[0]
|
|
|
|
message = "Let's send some random text!"
|
|
|
|
send_message(sender, message)
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Validate the first message got received")
|
2023-06-15 12:41:39 +02:00
|
|
|
for page in pages[1:]:
|
|
|
|
expect(page.get_by_text(message, exact=True)).to_be_visible()
|
|
|
|
|
|
|
|
# Send random text and validate it was received by other users
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Start sending random messages")
|
2023-06-15 12:41:39 +02:00
|
|
|
for i, sender in enumerate(pages):
|
|
|
|
receivers = pages[:i] + pages[i + 1:]
|
|
|
|
random_text = get_random_text()
|
|
|
|
|
|
|
|
send_message(sender, random_text)
|
|
|
|
for receiver in receivers:
|
|
|
|
expect(receiver.get_by_text(random_text, exact=True)).to_be_visible()
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Message received by all users")
|
2023-06-15 12:41:39 +02:00
|
|
|
|
|
|
|
# --------------------
|
|
|
|
# Close all users
|
2023-06-16 17:14:22 +02:00
|
|
|
log_note("Close all browsers")
|
2023-06-15 12:41:39 +02:00
|
|
|
for page in pages:
|
|
|
|
page.close()
|
|
|
|
|
|
|
|
for context in contexts:
|
|
|
|
context.close()
|
|
|
|
|
|
|
|
for browser in browsers:
|
|
|
|
browser.close()
|
2023-06-09 10:43:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
with sync_playwright() as playwright:
|
|
|
|
conversation_link = create_conversation(playwright)
|
|
|
|
talk(playwright, conversation_link)
|