#!/usr/bin/env python3 # Selenium/Firefox test script for gio demo. # Requires LibreWolf + geckodriver + a real GPU display (not headless Xvfb). # Run with: DISPLAY=:0 python3 test_firefox.py (or from the desktop) from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.firefox.service import Service from selenium.webdriver.common.action_chains import ActionChains import time URL = 'http://localhost:8765/' def make_driver(): opts = Options() opts.binary_location = '/usr/lib/librewolf/librewolf' # No --headless: needs real GPU for WebGL2 svc = Service('/bin/geckodriver', log_output='/dev/null') driver = webdriver.Firefox(service=svc, options=opts) driver.set_window_size(1280, 900) return driver def test_button_click(driver): driver.get(URL) time.sleep(3) canvas = driver.find_element('tag name', 'canvas') cw = canvas.size['width'] ch = canvas.size['height'] # Click "Click me!" button at ~(50, 67) ac = ActionChains(driver) ac.move_to_element_with_offset(canvas, -cw//2 + 50, -ch//2 + 67) ac.click() ac.perform() time.sleep(0.5) driver.save_screenshot('/tmp/gio-after-click.png') print('Button click: screenshot at /tmp/gio-after-click.png') def test_scrollbar_drag(driver): # Mouse down on scrollbar (right edge of list), drag down 80px script = ''' const canvas = document.querySelector('canvas[style*="fixed"]'); const rect = canvas.getBoundingClientRect(); const sectionPad = 12, thick = 6; const sbX = rect.left + rect.width - sectionPad - thick/2; // List viewport at ~40% down the page const listTopY = rect.top + rect.height * 0.4; const ev = (t, x, y, b) => canvas.dispatchEvent(new MouseEvent(t, { clientX: x, clientY: y, bubbles: true, buttons: b||0, button: 0 })); ev('mousedown', sbX, listTopY, 1); for (let i = 1; i <= 10; i++) ev('mousemove', sbX, listTopY + i*8, 1); ev('mouseup', sbX, listTopY+80, 0); return 'drag done'; ''' result = driver.execute_script(script) time.sleep(0.5) driver.save_screenshot('/tmp/gio-after-scroll.png') print(f'Scrollbar drag: {result}, screenshot at /tmp/gio-after-scroll.png') if __name__ == '__main__': driver = make_driver() try: test_button_click(driver) test_scrollbar_drag(driver) finally: driver.quit()