Skip to content

Instantly share code, notes, and snippets.

@lilinor
Last active January 9, 2025 17:05
Show Gist options
  • Select an option

  • Save lilinor/4c1ac80b4610fc8aac7291806b012bd7 to your computer and use it in GitHub Desktop.

Select an option

Save lilinor/4c1ac80b4610fc8aac7291806b012bd7 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import pytest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.android import UiAutomator2Options
def create_android_driver(udid, systemPort):
# Setting capabilities directly on the options object
capabilities = {
"appium:deviceName": "Genymotion Cloud PaaS",
"platformName": "Android",
"automationName": "UiAutomator2",
"appium:udid": udid,
"appium:systemPort": systemPort,
"appium:appPackage": "com.android.settings",
"appium:appActivity": ".Settings"
}
url = "http://localhost:4723"
options = UiAutomator2Options()
options.load_capabilities(capabilities)
driver = webdriver.Remote(url, options=options)
# Return the driver
return driver
@pytest.mark.parametrize(
"udid, systemPort",
[
("localhost:10000", "8201"),
("localhost:20000", "8202"),
("localhost:30000", "8203"),
],
)
def test_sum(udid, systemPort): # Accept udid and systemPort as parameters
driver = create_android_driver(udid, systemPort)
try:
driver.find_element(by=AppiumBy.XPATH, value='//*[@text="Battery"]')
finally:
# Ensure proper teardown
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment