|
| 1 | +import pytest |
| 2 | +from appium import webdriver |
| 3 | +from appium.options.android import UiAutomator2Options |
| 4 | + |
| 5 | +from drivers.driver_factory import Driver |
| 6 | + |
| 7 | + |
| 8 | +# from src.drivers.driver_factory import Driver |
| 9 | + |
| 10 | + |
| 11 | +@pytest.hookimpl |
| 12 | +def pytest_addoption(parser): |
| 13 | + """ |
| 14 | + Adds command-line options for pytest. |
| 15 | + """ |
| 16 | + parser.addoption( |
| 17 | + "--app", action="store", default="ios", help="Define App: ios or android" |
| 18 | + ) |
| 19 | + parser.addoption( |
| 20 | + "--device", action="store", default="emulator", help="Define Device Type" |
| 21 | + ) |
| 22 | + parser.addoption( |
| 23 | + "--platform", action="store", default="ios", help="Define Platform" |
| 24 | + ) |
| 25 | + parser.addoption( |
| 26 | + "--env", |
| 27 | + action="store", |
| 28 | + default="stage", |
| 29 | + help="Define test environment (e.g., stage, prod)", |
| 30 | + ) |
| 31 | + parser.addoption( |
| 32 | + "--listeners", |
| 33 | + action="store", |
| 34 | + default="events", |
| 35 | + help="Define listeners for the test run", |
| 36 | + ) |
| 37 | + |
| 38 | + |
| 39 | +@pytest.fixture(scope="session") |
| 40 | +def app(request): |
| 41 | + """ |
| 42 | + Retrieves the application type specified via the --app command-line option. |
| 43 | + """ |
| 44 | + return request.config.getoption("--app") |
| 45 | + |
| 46 | + |
| 47 | +@pytest.fixture(scope="session") |
| 48 | +def device(request): |
| 49 | + """ |
| 50 | + Retrieves the device type specified via the --device command-line option. |
| 51 | + """ |
| 52 | + return request.config.getoption("--device") |
| 53 | + |
| 54 | + |
| 55 | +@pytest.fixture(scope="function") |
| 56 | +def driver(request): |
| 57 | + platform = request.config.getoption("--platform") |
| 58 | + try: |
| 59 | + driver = Driver.get_driver(platform) |
| 60 | + except Exception as e: |
| 61 | + pytest.fail(f"Failed to initialize driver: {e}") |
| 62 | + |
| 63 | + yield driver |
| 64 | + driver.quit() |
0 commit comments