ci: fix dashboard tests (again)
This commit is contained in:
parent
44d533fe6d
commit
3004e32473
|
@ -3,6 +3,7 @@ import time
|
||||||
import unittest
|
import unittest
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
import logging
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
|
@ -12,6 +13,9 @@ from selenium.webdriver.support.wait import WebDriverWait
|
||||||
from selenium.webdriver.common import utils
|
from selenium.webdriver.common import utils
|
||||||
from selenium.common.exceptions import NoSuchElementException
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def driver():
|
def driver():
|
||||||
options = Options()
|
options = Options()
|
||||||
|
@ -31,39 +35,52 @@ def dashboard_url(dashboard_host, dashboard_port):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
return f"http://{dashboard_host}:{dashboard_port}"
|
return f"http://{dashboard_host}:{dashboard_port}"
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def login(driver, dashboard_url):
|
def login(driver, dashboard_url):
|
||||||
# admin is set in CI jobs, hence as default value
|
# admin is set in CI jobs, hence as default value
|
||||||
password = os.getenv("EMQX_DASHBOARD__DEFAULT_PASSWORD", "admin")
|
password = os.getenv("EMQX_DASHBOARD__DEFAULT_PASSWORD", "admin")
|
||||||
driver.get(dashboard_url)
|
driver.get(dashboard_url)
|
||||||
assert "EMQX Dashboard" == driver.title
|
assert "EMQX Dashboard" == driver.title
|
||||||
assert f"{dashboard_url}/#/login?to=/dashboard/overview" == driver.current_url
|
assert f"{dashboard_url}/#/login?to=/dashboard/overview" == driver.current_url
|
||||||
driver.find_element(By.XPATH, "//div[@class='login']//form[1]//input[@type='text']").send_keys("admin")
|
driver.execute_script("window.localStorage.setItem('licenseTipVisible','false');")
|
||||||
driver.find_element(By.XPATH, "//div[@class='login']//form[1]//input[@type='password']").send_keys(password)
|
driver.find_element(By.XPATH, "//div[@class='login']//form//input[@type='text']").send_keys("admin")
|
||||||
driver.find_element(By.XPATH, "//div[@class='login']//form[1]//button[1]").click()
|
driver.find_element(By.XPATH, "//div[@class='login']//form//input[@type='password']").send_keys(password)
|
||||||
|
driver.find_element(By.XPATH, "//div[@class='login']//form//button").click()
|
||||||
dest_url = urljoin(dashboard_url, "/#/dashboard/overview")
|
dest_url = urljoin(dashboard_url, "/#/dashboard/overview")
|
||||||
driver.get(dest_url)
|
|
||||||
ensure_current_url(driver, dest_url)
|
ensure_current_url(driver, dest_url)
|
||||||
|
assert len(driver.find_elements(By.XPATH, "//div[@class='login']")) == 0
|
||||||
|
logger.info(f"Logged in to {dashboard_url}")
|
||||||
|
|
||||||
def ensure_current_url(driver, url):
|
def ensure_current_url(d, url):
|
||||||
count = 0
|
count = 0
|
||||||
while url != driver.current_url:
|
while url != d.current_url:
|
||||||
if count == 10:
|
if count == 10:
|
||||||
raise Exception(f"Failed to load {url}")
|
raise Exception(f"Failed to load {url}")
|
||||||
count += 1
|
count += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def title(driver):
|
def title(d):
|
||||||
return driver.find_element("xpath", "//div[@id='app']//h1[@class='header-title']")
|
title = ''
|
||||||
|
for _ in range(5):
|
||||||
|
try:
|
||||||
|
title = d.find_element("xpath", "//div[@id='app']//h1[@class='header-title']")
|
||||||
|
break
|
||||||
|
except NoSuchElementException:
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
raise AssertionError("Cannot find the title element")
|
||||||
|
return title
|
||||||
|
|
||||||
def wait_title_text(driver, text):
|
def wait_title_text(d, text):
|
||||||
return WebDriverWait(driver, 10).until(lambda x: title(x).text == text)
|
return WebDriverWait(d, 10).until(lambda x: title(x).text == text)
|
||||||
|
|
||||||
def test_basic(driver, login, dashboard_url):
|
def test_basic(driver, dashboard_url):
|
||||||
driver.get(dashboard_url)
|
login(driver, dashboard_url)
|
||||||
|
logger.info(f"Current URL: {driver.current_url}")
|
||||||
wait_title_text(driver, "Cluster Overview")
|
wait_title_text(driver, "Cluster Overview")
|
||||||
|
|
||||||
def test_log(driver, login, dashboard_url):
|
def test_log(driver, dashboard_url):
|
||||||
|
login(driver, dashboard_url)
|
||||||
|
logger.info(f"Current URL: {driver.current_url}")
|
||||||
dest_url = urljoin(dashboard_url, "/#/log")
|
dest_url = urljoin(dashboard_url, "/#/log")
|
||||||
driver.get(dest_url)
|
driver.get(dest_url)
|
||||||
ensure_current_url(driver, dest_url)
|
ensure_current_url(driver, dest_url)
|
||||||
|
@ -95,10 +112,9 @@ def fetch_version(url):
|
||||||
version_str = info['rel_vsn']
|
version_str = info['rel_vsn']
|
||||||
return parse_version(version_str)
|
return parse_version(version_str)
|
||||||
|
|
||||||
def test_docs_link(driver, login, dashboard_url):
|
def test_docs_link(driver, dashboard_url):
|
||||||
dest_url = urljoin(dashboard_url, "/#/dashboard/overview")
|
login(driver, dashboard_url)
|
||||||
driver.get(dest_url)
|
logger.info(f"Current URL: {driver.current_url}")
|
||||||
ensure_current_url(driver, dest_url)
|
|
||||||
xpath_link_help = "//div[@id='app']//div[@class='nav-header']//a[contains(@class, 'link-help')]"
|
xpath_link_help = "//div[@id='app']//div[@class='nav-header']//a[contains(@class, 'link-help')]"
|
||||||
# retry up to 5 times
|
# retry up to 5 times
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
version: '3.9'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
emqx:
|
emqx:
|
||||||
image: ${_EMQX_DOCKER_IMAGE_TAG:-emqx/emqx:latest}
|
image: ${_EMQX_DOCKER_IMAGE_TAG:-emqx/emqx:latest}
|
||||||
environment:
|
environment:
|
||||||
EMQX_DASHBOARD__DEFAULT_PASSWORD: admin
|
EMQX_DASHBOARD__DEFAULT_PASSWORD: admin
|
||||||
|
EMQX_LOG__CONSOLE__LEVEL: debug
|
||||||
|
|
||||||
selenium:
|
selenium:
|
||||||
shm_size: '2gb'
|
shm_size: '2gb'
|
||||||
image: ghcr.io/emqx/selenium-chrome:1.0.0
|
image: ghcr.io/emqx/selenium-chrome:1.0.0
|
||||||
|
platform: linux/amd64
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
Loading…
Reference in New Issue