Skip to content

Commit

Permalink
Improve reliability of end-to-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Oct 31, 2023
1 parent 8df6155 commit 4e7901e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/e2e/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
Expand Down Expand Up @@ -676,13 +676,20 @@ def _click_button(self, icon: str, index: int) -> None:
sleep(0.01)

def _set_input(self, icon: str, index: int, value: str) -> None:
def contains_icon(e: WebElement) -> bool:
try:
return e.find_elements(
by=By.XPATH, value=f".//i[@class='fas fa-{icon}']"
) or e.find_elements(by=By.XPATH, value=f".//span[text()='{icon}']")
except StaleElementReferenceException:
return False

controls = [
e
for e in self._driver.find_elements(
by=By.XPATH, value="//div[contains(@class, 'control')]"
)
if e.find_elements(by=By.XPATH, value=f".//i[@class='fas fa-{icon}']")
or e.find_elements(by=By.XPATH, value=f".//span[text()='{icon}']")
if contains_icon(e)
]
inp = controls[index].find_element(by=By.TAG_NAME, value="input")
clear(inp)
Expand Down

0 comments on commit 4e7901e

Please sign in to comment.