Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements #23

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ def android_chrome():
capabilities = dict(
platformName="Android",
browserName="chrome",
chromeOptions={"w3c": False},
uiautomator2ServerLaunchTimeout=60000,
)
appium_server_url = "http://localhost:4723"
client_config = ClientConfig(appium_server_url)
command_executor = AppiumConnection(client_config=client_config)
return Remote(
command_executor, options=UiAutomator2Options().load_capabilities(capabilities)
)
options = UiAutomator2Options()
options.load_capabilities(capabilities)
return Remote(command_executor, options=options)


@pytest.fixture(params=ALL_BROWSERS)
Expand Down
19 changes: 10 additions & 9 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ def test_main(driver: BaseWebDriver):
with get_server_url() as webapp_url:
driver.get(webapp_url)
WebDriverWait(driver, TIMEOUT).until(
EC.element_to_be_clickable((By.ID, "about"))
EC.element_to_be_clickable((By.XPATH, "//*[@id='about']"))
)
about = driver.find_element(By.ID, "about")
assert about.get_attribute("innerText") == "About 24/7 Bishops"
about_popup = driver.find_element(By.ID, "about_popup")
about = driver.find_element(By.XPATH, "//*[@id='about']")
assert about.text == "About 24/7 Bishops"
about_popup = driver.find_element(By.XPATH, "//*[@id='about_popup']")
assert not about_popup.is_displayed()
about.click()
WebDriverWait(driver, TIMEOUT).until(
EC.visibility_of_element_located((By.ID, "about_popup"))
EC.visibility_of_element_located((By.XPATH, "//*[@id='about_popup']"))
)
assert (
"GNU Affero General Public License"
in driver.find_element(By.XPATH, "//*[@id='about_popup']").text
)
assert "GNU Affero General Public License" in driver.find_element(
By.ID, "about_popup"
).get_attribute("innerText")
assert about_popup.is_displayed()
driver.find_element(By.ID, "close_about_popup").click()
driver.find_element(By.XPATH, "//*[@id='close_about_popup']").click()
WebDriverWait(driver, TIMEOUT).until(lambda d: not about_popup.is_displayed())


Expand Down
24 changes: 12 additions & 12 deletions tests/test_work_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

def get_element(driver: BaseWebDriver, square: str):
if square is None:
return driver.find_element(By.ID, "move_list")
return driver.find_element(By.XPATH, "//*[@id='move_list']")
row = 8 - int(square[1])
column = ord(square[0]) - 97
return driver.find_element(By.ID, f"work_board_{8*row+column}")
return driver.find_element(By.XPATH, f"//*[@id='work_board_{8*row+column}']")


def make_move(
Expand All @@ -24,8 +24,8 @@ def make_move(
move_list_append: str = "",
promotion_piece=None,
):
move_list = driver.find_element(By.ID, "move_list")
orig_move_list = move_list.get_attribute("innerHTML")
move_list = driver.find_element(By.XPATH, "//*[@id='move_list']")
orig_move_list = move_list.text
from_elmt = get_element(driver, from_square)
to_elmt = get_element(driver, to_square)
ActionChains(driver).drag_and_drop(from_elmt, to_elmt).perform()
Expand All @@ -34,20 +34,20 @@ def make_move(
assert alert.text == "Promotion piece (q, r, b, or n)?"
alert.send_keys(promotion_piece)
alert.accept()
assert move_list.get_attribute("innerHTML") == orig_move_list + move_list_append
assert move_list.text == orig_move_list + move_list_append


def test_work_board(driver: BaseWebDriver):
if isinstance(driver, Firefox):
return # Drag/drop doesn't work with Firefox geckodriver: https://bugzilla.mozilla.org/show_bug.cgi?id=1515879
return # Drag/drop doesn't work with Firefox geckodriver: https://github.com/mozilla/geckodriver/issues/1450
with get_server_url() as webapp_url:
driver.get(webapp_url)
WebDriverWait(driver, TIMEOUT).until(
EC.element_to_be_clickable((By.ID, "work_board"))
EC.element_to_be_clickable((By.XPATH, "//*[@id='work_board']"))
)
driver.find_element(By.ID, "work_board").click()
driver.find_element(By.XPATH, "//*[@id='work_board']").click()
WebDriverWait(driver, TIMEOUT).until(
EC.visibility_of_element_located((By.ID, "work_board_table"))
EC.visibility_of_element_located((By.XPATH, "//*[@id='work_board_table']"))
)
make_move(driver, "e2", "e4", "1. e4")
make_move(driver, "e7", "d6") # Illegal move
Expand All @@ -63,8 +63,8 @@ def test_work_board(driver: BaseWebDriver):
make_move(driver, "f3", "g2", " fxg2")
make_move(driver, "g7", "h8", " 6. gxh8=Q", "q")
make_move(driver, "g2", "h1", " gxh1=N", "n")
driver.find_element(By.ID, "work_board_back").click()
move_list = driver.find_element(By.ID, "move_list")
driver.find_element(By.XPATH, "//*[@id='work_board_back']").click()
move_list = driver.find_element(By.XPATH, "//*[@id='move_list']")
WebDriverWait(driver, TIMEOUT).until(
lambda d: move_list.get_attribute("innerHTML").endswith("6. gxh8=Q")
lambda d: move_list.text.endswith("6. gxh8=Q")
)
Loading