appium: Autostart server
This commit is contained in:
1 parent
8bba8fb827
commit
755464e8d9
5 files changed
+39
-6
No files matched your search
@@ -2,6 +2,8 @@ import os
|
||||
|
||||
|
||||
class Config:
|
||||
APPIUM_HOST = os.environ.get("APPIUM_HOST", "http://127.0.0.1:4723")
|
||||
ANDROID_HOME = os.environ.get("ANDROID_HOME", os.path.expanduser("~/Android/Sdk"))
|
||||
APPIUM_HOST = os.environ.get("APPIUM_HOST", "127.0.0.10") # Avoid collisions with manually started Appium servers
|
||||
APPIUM_PORT = os.environ.get("APPIUM_PORT", "14723")
|
||||
QEMU_QMP_PATH = os.environ.get("QEMU_QMP_PATH")
|
||||
QEMU_MONITOR_PATH = os.environ.get("QEMU_MONITOR_PATH")
|
||||
@@ -1,9 +1,11 @@
|
||||
import os
|
||||
import traceback
|
||||
from typing import Generator
|
||||
|
||||
import appium
|
||||
import pytest
|
||||
from appium.options.android import UiAutomator2Options
|
||||
from appium.webdriver.appium_service import AppiumService
|
||||
from appium.webdriver.client_config import AppiumClientConfig
|
||||
|
||||
from etchdroid import package_name
|
||||
@@ -12,11 +14,28 @@ from etchdroid.qemu import QEMUController
|
||||
from etchdroid.utils import execute_script
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def appium_service():
|
||||
if not os.path.exists(Config.ANDROID_HOME):
|
||||
raise RuntimeError(f"ANDROID_HOME environment variable is not set or points to an invalid directory")
|
||||
os.environ["ANDROID_HOME"] = Config.ANDROID_HOME
|
||||
|
||||
service = AppiumService()
|
||||
service.start(
|
||||
# Check the output of `appium server --help` for the complete list of
|
||||
# server command line arguments
|
||||
args=["--address", Config.APPIUM_HOST, "-p", Config.APPIUM_PORT, "--allow-insecure=adb_shell"],
|
||||
timeout_ms=20000,
|
||||
)
|
||||
yield service
|
||||
service.stop()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def driver() -> Generator[appium.webdriver.Remote, None, None]:
|
||||
def driver(appium_service) -> Generator[appium.webdriver.Remote, None, None]:
|
||||
options = UiAutomator2Options()
|
||||
options.app_package = package_name
|
||||
client_config = AppiumClientConfig(remote_server_addr=Config.APPIUM_HOST)
|
||||
client_config = AppiumClientConfig(remote_server_addr=f"http://{Config.APPIUM_HOST}:{Config.APPIUM_PORT}")
|
||||
_driver = appium.webdriver.Remote(
|
||||
options=UiAutomator2Options(),
|
||||
client_config=client_config,
|
||||
|
||||
@@ -8,6 +8,13 @@ from selenium.common import ElementNotVisibleException, NoSuchElementException
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
|
||||
def used(*a, **k):
|
||||
"""
|
||||
Used to mark a function as used, so that it is not removed by the linter.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def execute_script(driver: appium.webdriver.Remote, script: str, *args: Any) -> Any:
|
||||
return driver.execute_script(script, *args)
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import appium.webdriver
|
||||
|
||||
from etchdroid import actions as app
|
||||
from etchdroid.fixtures import driver
|
||||
from etchdroid.utils import device_temp_sparse_file, wait_for_element
|
||||
from etchdroid.fixtures import appium_service, driver
|
||||
from etchdroid.utils import device_temp_sparse_file, used, wait_for_element
|
||||
|
||||
used(appium_service)
|
||||
|
||||
|
||||
def test_regular_flow(driver: appium.webdriver.Remote):
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import appium.webdriver
|
||||
import pytest
|
||||
|
||||
from etchdroid.fixtures import driver, qemu
|
||||
from etchdroid.fixtures import appium_service, driver, qemu
|
||||
from etchdroid.qemu import QEMUController
|
||||
from etchdroid.utils import used
|
||||
|
||||
used(appium_service)
|
||||
|
||||
|
||||
@pytest.mark.qemu
|
||||
|
||||
Reference in new issue
Block a user