2023-08-04 19:33:57 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-03-09 08:44:06 -05:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
if sys.platform == 'haiku1':
|
2024-11-25 09:35:55 -05:00
|
|
|
print('Automation tests are disabled on Haiku.')
|
|
|
|
exit(0)
|
2024-03-09 08:44:06 -05:00
|
|
|
|
2024-11-28 17:51:22 -05:00
|
|
|
import selenium
|
2023-08-02 20:30:48 -04:00
|
|
|
from selenium import webdriver
|
2024-02-21 20:06:25 -05:00
|
|
|
from selenium.webdriver.firefox.service import Service
|
2023-08-02 20:30:48 -04:00
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.support import expected_conditions
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
|
2024-11-28 17:51:22 -05:00
|
|
|
def select(driver, path, action = None):
|
|
|
|
start_time = time.time()
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
driver.switch_to.default_content()
|
|
|
|
context = driver
|
|
|
|
for node in path:
|
2024-11-28 19:58:51 -05:00
|
|
|
if node.startswith('#'):
|
|
|
|
context = context.find_element(By.ID, node[1:])
|
|
|
|
elif node.startswith('/'):
|
|
|
|
context = context.find_element(By.XPATH, node)
|
|
|
|
elif node.startswith('.'):
|
|
|
|
context = context.find_element(By.CLASS_NAME, node[1:])
|
|
|
|
elif node.startswith('='):
|
|
|
|
context = context.find_element(By.LINK_TEXT, node[1:])
|
|
|
|
elif node == 'frame':
|
2024-11-28 17:51:22 -05:00
|
|
|
driver.switch_to.frame(context)
|
|
|
|
context = driver
|
2024-11-28 19:58:51 -05:00
|
|
|
elif node == 'shadow_root':
|
|
|
|
context = context.shadow_root
|
2024-11-28 17:51:22 -05:00
|
|
|
else:
|
2024-11-28 19:58:51 -05:00
|
|
|
context = context.find_element(By.TAG_NAME, node)
|
2024-11-28 17:51:22 -05:00
|
|
|
if action is not None:
|
|
|
|
if action[0] == 'click':
|
|
|
|
context.click()
|
|
|
|
elif action[0] == 'send_keys':
|
|
|
|
context.send_keys(action[1])
|
|
|
|
elif action[0] == 'clear':
|
|
|
|
context.clear()
|
|
|
|
else:
|
|
|
|
raise RuntimeError(f'Unexpected action: {action}.')
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
return context
|
2024-11-28 19:58:51 -05:00
|
|
|
except (selenium.common.exceptions.NoSuchElementException,
|
|
|
|
selenium.common.exceptions.NoSuchShadowRootException,
|
|
|
|
selenium.common.exceptions.StaleElementReferenceException,
|
|
|
|
selenium.common.exceptions.WebDriverException):
|
2024-11-28 17:51:22 -05:00
|
|
|
if time.time() - start_time < 5.0:
|
|
|
|
time.sleep(0.1)
|
|
|
|
pass
|
2023-08-02 20:44:35 -04:00
|
|
|
|
2024-01-11 18:57:02 -05:00
|
|
|
success = False
|
2023-08-02 20:30:48 -04:00
|
|
|
try:
|
|
|
|
options = webdriver.FirefoxOptions()
|
2024-02-21 20:06:25 -05:00
|
|
|
service = Service(log_output = 'out/geckodriver.log')
|
2023-08-02 20:30:48 -04:00
|
|
|
#options.add_argument('--headless')
|
2024-02-21 20:06:25 -05:00
|
|
|
driver = webdriver.Firefox(options = options, service = service)
|
2023-08-09 18:38:41 -04:00
|
|
|
wait = WebDriverWait(driver, 10)
|
2024-09-17 12:47:28 -04:00
|
|
|
|
|
|
|
driver.get('http://localhost:8888')
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'adminuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'admin_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'admin_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame', '=identity'])
|
2024-09-17 12:47:28 -04:00
|
|
|
|
|
|
|
driver.get('http://localhost:8888/~core/admin/')
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '#gs_room_name'], ('send_keys', 'test room'))
|
|
|
|
select(driver, ['#document', 'frame', '//*[@id="gs_room_name"]/following-sibling::button'], ('click',))
|
2024-11-30 16:58:48 -05:00
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
2024-09-17 12:47:28 -04:00
|
|
|
driver.switch_to.alert.accept()
|
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
2024-09-17 12:47:28 -04:00
|
|
|
|
2023-08-02 20:30:48 -04:00
|
|
|
driver.get('http://localhost:8888')
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['#document'])
|
|
|
|
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#create_identity'], ('click',))
|
2024-11-28 17:51:22 -05:00
|
|
|
wait.until(expected_conditions.alert_is_present()).accept()
|
2023-08-02 20:30:48 -04:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#id_dropdown', '//button[position()=2]'], ('click',))
|
2024-11-25 09:35:55 -05:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '.tf-profile', 'shadow_root', '#edit_profile'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '.tf-profile', 'shadow_root', '#name'], ('send_keys', 'user'))
|
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '.tf-profile', 'shadow_root', '#save_profile'], ('click',))
|
2024-11-25 09:35:55 -05:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
2024-11-25 09:35:55 -05:00
|
|
|
|
2024-10-23 18:48:42 -04:00
|
|
|
driver.get('http://localhost:8888/~testuser/test/')
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document'])
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#close_error'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '=edit'], ('click',))
|
|
|
|
select(driver, ['#editor', '.cm-content'], ('click',))
|
|
|
|
select(driver, ['#editor', '.cm-content'], ('send_keys', 'app.setDocument(\n\t"<div id=\'test-div\'>Hello, world!</div>"\n);'))
|
|
|
|
select(driver, ['#save'], ('click',))
|
2024-11-28 17:51:22 -05:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '#test-div'])
|
2024-10-23 18:48:42 -04:00
|
|
|
|
2024-11-25 09:35:55 -05:00
|
|
|
size = driver.get_window_size()
|
|
|
|
driver.set_window_size(1200, 540)
|
|
|
|
driver.save_screenshot('out/screenshot0.png')
|
|
|
|
driver.set_window_size(size['width'], size['height'])
|
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#editor', '.cm-content'], ('click',))
|
|
|
|
select(driver, ['#editor', '.cm-content'], ('clear',))
|
|
|
|
select(driver, ['#editor', '.cm-content'], ('send_keys', 'app.setDocument("<div id=\'test-div2\'>Hello, world, again!</div>")'))
|
|
|
|
select(driver, ['#save'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame', '#test-div2'])
|
2024-10-27 14:05:20 -04:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#delete'], ('click',))
|
2024-10-25 12:34:22 -04:00
|
|
|
wait.until(expected_conditions.alert_is_present()).accept()
|
2024-10-23 18:48:42 -04:00
|
|
|
wait.until(expected_conditions.alert_is_present()).dismiss()
|
2024-10-25 12:34:22 -04:00
|
|
|
driver.get('http://localhost:8888/~testuser/test/')
|
2024-10-23 18:48:42 -04:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document'])
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#close_error'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '=edit'], ('click',))
|
2024-10-23 18:48:42 -04:00
|
|
|
|
2024-11-28 17:51:22 -05:00
|
|
|
driver.get('http://localhost:8888')
|
2024-11-25 09:35:55 -05:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '=identity'])
|
2024-04-13 20:32:17 -04:00
|
|
|
|
2024-11-25 09:35:55 -05:00
|
|
|
size = driver.get_window_size()
|
|
|
|
driver.set_window_size(540, 1200)
|
|
|
|
driver.save_screenshot('out/screenshot1.png')
|
|
|
|
driver.set_window_size(size['width'], size['height'])
|
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '=identity'], ('click',))
|
2024-04-13 20:32:17 -04:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '#create_id'], ('click',))
|
|
|
|
id0 = select(driver, ['#document', 'frame', 'li']).text.split(' ')[-1]
|
2024-11-28 17:51:22 -05:00
|
|
|
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '//li/button[text()="Export Identity"]'], ('click',))
|
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
|
|
|
words = select(driver, ['#document', 'frame', '//li//textarea']).get_attribute('value')
|
|
|
|
select(driver, ['#document', 'frame', '//li/button[text()="Delete Identity"]'], ('click',))
|
2024-01-06 14:52:14 -05:00
|
|
|
driver.switch_to.alert.send_keys('DELETE')
|
|
|
|
driver.switch_to.alert.accept()
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
2024-01-06 14:52:14 -05:00
|
|
|
driver.switch_to.alert.accept()
|
2024-11-28 19:58:51 -05:00
|
|
|
words = select(driver, ['#document', 'frame', '//textarea'], ('send_keys', words))
|
|
|
|
select(driver, ['#document', 'frame', '//button[text()="Import Identity"]'], ('click',))
|
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
2024-01-06 14:52:14 -05:00
|
|
|
driver.switch_to.alert.accept()
|
|
|
|
driver.switch_to.frame(wait.until(expected_conditions.presence_of_element_located((By.ID, 'document'))))
|
2024-11-28 19:58:51 -05:00
|
|
|
id1 = select(driver, ['#document', 'frame', 'li']).text.split(' ')[-1]
|
2024-11-28 17:51:22 -05:00
|
|
|
assert id0 == id1
|
2024-01-06 14:52:14 -05:00
|
|
|
|
|
|
|
driver.get('http://localhost:8888')
|
2024-11-28 19:58:51 -05:00
|
|
|
select(driver, ['#document', 'frame', '=ssb'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#edit'], ('send_keys', 'Hello, world!'))
|
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#submit'], ('click',))
|
|
|
|
select(driver, ['//button[text()="✅ Allow"]'], ('click',))
|
|
|
|
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#login_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#guest_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#guestButton'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root'])
|
|
|
|
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#login_label'], ('click',))
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'wrong_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'wrong_user'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'wrong_test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'wrong_test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', '😁'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#change_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#new_password'], ('send_keys', 'new_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#confirm'], ('send_keys', 'new_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame'])
|
|
|
|
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
|
|
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#login_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'test_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#error'])
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#login_label'], ('click',))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#password'], ('send_keys', 'new_password'))
|
|
|
|
select(driver, ['tf-auth', 'shadow_root', '#loginButton'], ('click',))
|
|
|
|
select(driver, ['#document', 'frame'])
|
2023-09-22 18:59:26 -04:00
|
|
|
|
2024-01-11 18:57:02 -05:00
|
|
|
success = True
|
2023-08-02 20:30:48 -04:00
|
|
|
finally:
|
|
|
|
driver.close()
|
|
|
|
driver.quit()
|
|
|
|
|
2024-01-11 18:57:02 -05:00
|
|
|
if success:
|
|
|
|
print('\033[92mTEST SUCCEEDED.\033[0m')
|
|
|
|
else:
|
|
|
|
print('\033[91mTEST FAILED.\033[0m')
|