From 4d432b6e76941dbaad10915019bcb3caf6a6695a Mon Sep 17 00:00:00 2001 From: Chuck Cadman <51368516+cdcadman@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:58:06 -0800 Subject: [PATCH 1/2] Remove dependence on deprecated JSON Wire protocol --- tests/conftest.py | 7 +++---- tests/test_main.py | 19 ++++++++++--------- tests/test_work_board.py | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index afeaa70..e1a32f4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_main.py b/tests/test_main.py index c716e39..7b76b99 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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()) diff --git a/tests/test_work_board.py b/tests/test_work_board.py index 736ea33..5d46034 100644 --- a/tests/test_work_board.py +++ b/tests/test_work_board.py @@ -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( @@ -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() @@ -34,7 +34,7 @@ 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): @@ -43,11 +43,11 @@ def test_work_board(driver: BaseWebDriver): 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 @@ -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") ) From f51b4ebeee165c8cce07514099cac67c804fbd9c Mon Sep 17 00:00:00 2001 From: Chuck Cadman <51368516+cdcadman@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:20:24 -0800 Subject: [PATCH 2/2] Improve link for Firefox drag/drop issue --- tests/test_work_board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_work_board.py b/tests/test_work_board.py index 5d46034..5190f98 100644 --- a/tests/test_work_board.py +++ b/tests/test_work_board.py @@ -39,7 +39,7 @@ def make_move( 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(