diff --git a/appium-tests/etchdroid/actions.py b/appium-tests/etchdroid/actions.py index 4655451..077edb9 100644 --- a/appium-tests/etchdroid/actions.py +++ b/appium-tests/etchdroid/actions.py @@ -7,9 +7,9 @@ from etchdroid import package_name from etchdroid.utils import wait_for_element, run_adb_command -def basic_flow(driver: Remote, image_prefix: str, image_suffix: str): +def basic_flow(driver: Remote, image_filename: str): tap_write_image(driver) - find_and_open_file(driver, image_prefix, image_suffix) + find_and_open_file(driver, image_filename) select_first_usb_device_if_multiple(driver) grant_usb_permission(driver) confirm_write_image(driver) @@ -21,14 +21,14 @@ def tap_write_image(driver: Remote): btn.click() -def find_and_open_file(driver: Remote, prefix: str, suffix: str): +def find_and_open_file(driver: Remote, filename: str): search_btn = wait_for_element(driver, '//*[@content-desc="Search"]') search_btn.click() search_field = wait_for_element(driver, "//android.widget.AutoCompleteTextView") - search_field.send_keys(f"{prefix}") + search_field.send_keys(f"{filename}") arch_iso = wait_for_element( driver, - f'//android.widget.TextView[starts-with(@text, "{prefix}") and ends-with(@text, "{suffix}")]', + f'//android.widget.TextView[@text="{filename}"]', 5, ) arch_iso.click() diff --git a/appium-tests/etchdroid/utils.py b/appium-tests/etchdroid/utils.py index cfc958b..bfaff1f 100644 --- a/appium-tests/etchdroid/utils.py +++ b/appium-tests/etchdroid/utils.py @@ -1,6 +1,8 @@ import tempfile +from collections import namedtuple from contextlib import contextmanager -from typing import Any +from pathlib import Path +from typing import Any, Generator import appium.webdriver from appium.webdriver.common.appiumby import AppiumBy @@ -85,6 +87,9 @@ def run_adb_command( return result +PathFilenamePair = namedtuple("PathFilenamePair", ["path", "filename"]) + + @contextmanager def device_temp_sparse_file( driver: appium.webdriver.Remote, @@ -92,7 +97,7 @@ def device_temp_sparse_file( name_suffix: str, size: int | str, path: str = "/sdcard/Download/", -): +) -> Generator[PathFilenamePair, None, None]: temp_file_name = tempfile.mktemp(prefix=name_prefix, suffix=name_suffix, dir=path) run_adb_command( driver, @@ -102,6 +107,6 @@ def device_temp_sparse_file( temp_file_name, ) try: - yield temp_file_name + yield PathFilenamePair(temp_file_name, Path(temp_file_name).name) finally: run_adb_command(driver, "rm", "-f", temp_file_name) diff --git a/appium-tests/tests/test_generic.py b/appium-tests/tests/test_generic.py index 4ef2221..4bec827 100644 --- a/appium-tests/tests/test_generic.py +++ b/appium-tests/tests/test_generic.py @@ -8,14 +8,14 @@ used(appium_service) def test_regular_flow(driver: appium.webdriver.Remote): - with device_temp_sparse_file(driver, "etchdroid_test_image_", ".iso", "1800M"): - app.basic_flow(driver, "etchdroid_test_image_", ".iso") + with device_temp_sparse_file(driver, "etchdroid_test_regular_flow_", ".iso", "1800M") as image: + app.basic_flow(driver, image.filename) app.wait_for_success(driver) def test_skip_verification(driver: appium.webdriver.Remote): - with device_temp_sparse_file(driver, "etchdroid_test_image_", ".iso", "1000M"): - app.basic_flow(driver, "etchdroid_test_image_", ".iso") + with device_temp_sparse_file(driver, "etchdroid_test_skip_verification_", ".iso", "1000M") as image: + app.basic_flow(driver, image.filename) app.skip_lay_flat_sheet(driver) skip_btn = app.get_skip_verify_button(driver) @@ -25,14 +25,14 @@ def test_skip_verification(driver: appium.webdriver.Remote): def test_windows_image_warning(driver: appium.webdriver.Remote): - with device_temp_sparse_file(driver, "etchdroid_test_image_windows_", ".iso", "1M") as image: - app.open_file(driver, image) + with device_temp_sparse_file(driver, "etchdroid_test_windows_image_warning_", ".iso", "1M") as image: + app.open_file(driver, image.path) wait_for_element(driver, '//android.view.View[@resource-id="confirmWindowsAlert"]') def test_image_too_large(driver: appium.webdriver.Remote): with device_temp_sparse_file(driver, "etchdroid_test_image_too_large_", ".iso", "100G") as image: - app.open_file(driver, image) + app.open_file(driver, image.path) app.select_first_usb_device_if_multiple(driver) app.grant_usb_permission(driver) app.confirm_write_image(driver) diff --git a/appium-tests/tests/test_qemu.py b/appium-tests/tests/test_qemu.py index cca121b..d75306f 100644 --- a/appium-tests/tests/test_qemu.py +++ b/appium-tests/tests/test_qemu.py @@ -53,7 +53,7 @@ def random_image_file(driver: appium.webdriver.Remote) -> Generator[tuple[str, b size_bytes = 10 * 1024 * 1024 # 10 MB payload = os.urandom(size_bytes) - remote_path = tempfile.mktemp(prefix="etchdroid_test_image_", suffix=".iso", dir="/sdcard/Download/") + remote_path = tempfile.mktemp(prefix="etchdroid_test_random_image_", suffix=".iso", dir="/sdcard/Download/") execute_script( driver, "mobile: pushFile", @@ -74,7 +74,7 @@ def raw_disk_image(qemu: QEMUController): tmp_path = Path(tmp_path) size_bytes = 50 * 1024 * 1024 # 50 MB - filename = tmp_path / "etchdroid_test_image.img" + filename = tmp_path / "etchdroid_test_raw_disk_image.img" # Write random data to the image to catch more bugs with open(filename, "wb") as f: @@ -124,8 +124,8 @@ def verify_written_image(payload: bytes, raw_blockdev: Path): @pytest.mark.qemu def test_unplug_xhci(driver: appium.webdriver.Remote, qemu: QEMUController): - with device_temp_sparse_file(driver, "etchdroid_test_image_", ".iso", "1800M"): - app.basic_flow(driver, "etchdroid_test_image_", ".iso") + with device_temp_sparse_file(driver, "etchdroid_test_unplug_xhci_", ".iso", "1800M") as image: + app.basic_flow(driver, image.filename) print("Waiting for write progress...") app.wait_for_write_progress(driver) @@ -146,7 +146,7 @@ def test_regular_flow_with_random_data_uhci( _, raw_disk_image_path = raw_usb_drive remote_fname = Path(remote_image_path).name - app.basic_flow(driver, remote_fname, ".iso") + app.basic_flow(driver, remote_fname) app.wait_for_success(driver) verify_written_image(image_payload, raw_disk_image_path) @@ -163,7 +163,7 @@ def test_unplug_with_random_data_uhci( raw_device_id, raw_disk_image_path = raw_usb_drive remote_fname = Path(remote_image_path).name - app.basic_flow(driver, remote_fname, ".iso") + app.basic_flow(driver, remote_fname) print("Waiting for write progress...") app.wait_for_write_progress(driver)