Skip to content

Commit

Permalink
added tests for HTML pages (#186)
Browse files Browse the repository at this point in the history
* added tests for project webpage
  • Loading branch information
beliaev-maksim authored Jul 5, 2022
1 parent f12058e commit ef222d5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ test = [
"mypy==0.960",
"pytest==6.2.5",
"pytest-cov==3.0.0",
"webdriver-manager",
"selenium>4",
]

deploy = [
Expand Down
1 change: 1 addition & 0 deletions tests/input/project_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"plots": [{"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=1 xs=0.5mm", "id": "a1", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [2.63819670610288e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=2 xs=0.5mm", "id": "a2", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [2.63723033290304e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=3 xs=0.6mm", "id": "a3", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [3.150045264625e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=1 xs=0.6mm", "id": "a4", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [3.15243139461569e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=2 xs=0.6mm", "id": "a5", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [3.15213626648844e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=3 xs=0.5mm", "id": "a6", "x_label": "\"Freq [Hz]\"", "y_label": "\"[W]\"", "x_axis": [10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [2.63698193285662e-06], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Force Plot 1:Force_left.Force_mag:xs=0.5mm", "id": "a7", "x_label": "\"Freq [Hz]\"", "y_label": "\"[newton]\"", "x_axis": [10, 505, 1000, 10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [8.838198367402493e-09, 8.838234897431875e-09, 8.838341638492361e-09, 8.852372512607002e-09], "diff": [], "delta": -1, "avg": -1}, {"name": "Maxwell2DDesign1:Force Plot 1:Force_left.Force_mag:xs=0.6mm", "id": "a8", "x_label": "\"Freq [Hz]\"", "y_label": "\"[newton]\"", "x_axis": [10, 505, 1000, 10000], "version_ref": -1, "y_axis_ref": [], "version_now": "221", "y_axis_now": [8.738467263395443e-09, 8.738477597163624e-09, 8.738507794517114e-09, 8.742503196027169e-09], "diff": [], "delta": -1, "avg": -1}], "error_exception": ["Design:Maxwell2DDesign1 Variation: xs=6.000000000e-01mm Setup: Setup1 has no mesh stats"], "mesh": [{"name": "Maxwell2DDesign1:Setup1:xs=0.5mm", "current": 133, "link": "reference_folder\\profiles\\_7GWPCH.mstat"}, {"name": "Maxwell2DDesign1:Setup1:xs=6.000000000e-01mm", "current": null, "link": "reference_folder\\profiles\\_SICOZ6.mstat"}], "simulation_time": [{"name": "Maxwell2DDesign1:Setup1:xs=0.5mm", "current": "00:00:00", "link": "reference_folder\\profiles\\_4LV88H.prof"}, {"name": "Maxwell2DDesign1:Setup1:xs=6.000000000e-01mm", "current": "00:00:07", "link": "reference_folder\\profiles\\_VMG6BS.prof"}], "slider_limit": 0, "max_avg": 0}
80 changes: 80 additions & 0 deletions tests/unittests/test_web_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager

from .test_aedt_test_runner import TESTS_DIR
from .test_aedt_test_runner import BaseElectronicsDesktopTester

options = FirefoxOptions()
options.headless = True

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()), options=options)


class TestProjectWebPage(BaseElectronicsDesktopTester):
def setup_class(self):
super().setup(self)
self.aedt_tester.only_reference = True

with open(TESTS_DIR / "input" / "project_report.json") as file:
proj_dict = json.load(file)

self.aedt_tester.initialize_results()
self.aedt_tester.render_project_html("just_winding_221", proj_dict)

self.webpage = f"file:///{self.aedt_tester.results_path / 'just_winding_221.html'}"
self.rel_path = str(self.aedt_tester.results_path).lower()
driver.get(str(self.webpage))

def teardown_class(self):
driver.close()

def test_title(self):
assert driver.title == "just_winding_221"

def test_simtime_link(self):
simtime_link = driver.find_element(
by=By.XPATH, value="/html/body/div/div/div/section/div[2]/div/div/div[2]/div/table/tbody/tr[2]/td[2]/a"
)
assert simtime_link.text == "00:00:07"

profile_path = Path(simtime_link.get_attribute("href").replace("file:///", ""))
assert profile_path.relative_to(self.rel_path) == Path("reference_folder", "profiles", "_VMG6BS.prof")

def test_sim_name(self):
sim_name = driver.find_element(
by=By.XPATH, value="/html/body/div/div/div/section/div[2]/div/div/div[2]/div/table/tbody/tr[1]/td[1]"
)
assert sim_name.text == "Maxwell2DDesign1:Setup1:xs=0.5mm"

def test_mesh_link(self):
mesh_link = driver.find_element(
by=By.XPATH, value="/html/body/div/div/div/section/div[3]/div/div/div[2]/div/table/tbody/tr[1]/td[2]/a"
)
assert mesh_link.text == "133"

profile_path = Path(mesh_link.get_attribute("href").replace("file:///", ""))
assert profile_path.relative_to(self.rel_path) == Path("reference_folder", "profiles", "_7GWPCH.mstat")

def test_mesh_name(self):
mesh_name = driver.find_element(
by=By.XPATH, value="/html/body/div/div/div/section/div[3]/div/div/div[2]/div/table/tbody/tr[2]/td[1]"
)
assert mesh_name.text == "Maxwell2DDesign1:Setup1:xs=6.000000000e-01mm"

def test_plot_button(self):
button = driver.find_element(by=By.XPATH, value="/html/body/div/div/div/section/div[8]/div/div/button")

assert button.text == "Maxwell2DDesign1:Loss Plot 1:SolidLoss:Pass=2 xs=0.6mm"

def test_error_messages(self):
msg = driver.find_element(
by=By.XPATH, value="/html/body/div/div/div/section/div[1]/div/div/div[2]/div/table/tbody/tr/td"
)

assert msg.text == "Design:Maxwell2DDesign1 Variation: xs=6.000000000e-01mm Setup: Setup1 has no mesh stats"

0 comments on commit ef222d5

Please sign in to comment.