Search code examples
pythonasync-awaitpython-asynciopython-appium

How to convert the Appium-Python code from Sync to Async


from time import sleep

import Asyncio as Asyncio
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy


desired_caps = {
    "app": "/home/ubuntu/mobile_automation/sample.apk",
    "platformName": "Android",
    "deviceName": "ubuntu",
    "ignoreHiddenApiPolicyError": "true",
    # "appium:udid": "emulator-5554",
    "unicodeKeyboard": True,
    "resetKeyboard": True,
    "autoGrantPermissions": True,
    "adbExecTimeout": 60000,
    "headless":True
}
try:
    # Connect to the appium server and open the app
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    driver.implicitly_wait(10)

    # Find and click the necessary elements
    bank_login_button = driver.find_element(by=AppiumBy.ID, value='com.indigo.sample:id/btn_register_login')
    bank_login_button.click()
    print("Webdriver Connected")

How to convert this appium python webdiver connection sync to async in python ?
is there any way to convert this?

I need an conversion of sync to async for appium webdriver in python. Any help would be appriciated


Solution

  • You can use loop = asyncio.get_event_loop() await loop.run_in_executor(None, webdriver.Remote, 'http://127.0.0.1:4723/wd/hub', desired_caps)