pythonappiumbluestacks

Python appium webdriver.Remote errors with 'NoneType' object has no attribute 'to_capabilities'


after setting up appium inspector, I was able to access to my BlueStack device from inspector

{ "platformName": "Android", "appium:deviceName": "localhost:5555", "appium:platformVersion": "7", "appium:ensureWebviewsHavePages": "true", "appium:automationName": "UiAutomator2" }

but accessing the device from python script it gives me error with

'NoneType' object has no attribute 'to_capabilities'

capabilities = dict(
    platformName='Android',
    automationName='uiautomator2',
    platformVersion='7',
    deviceName='localhost:5555',
    # appPackage='com.android.settings',
    # appActivity='.Settings',
    # language='en',
    # locale='US'
)

appium_server_url = 'http://localhost:4723'

class TestAppium(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Remote(appium_server_url, capabilities)

    def tearDown(self) -> None:
        if self.driver:
            self.driver.quit()

    def test_find_battery(self) -> None:
        el = self.driver.find_element(by=AppiumBy.XPATH, value='//*[@text="Battery"]')
        el.click()

if __name__ == '__main__':
    unittest.main()

what could I do to fix the issue? Thanks a head for the responses

fyi: device name - adb devices -l List of devices attached emulator-5554 device product:OnePlus5 model:ONEPLUS_A5000 device:OnePlus5 transport_id:1 localhost:5555 device product:OnePlus5 model:ONEPLUS_A5000 device:OnePlus5 transport_id:3

tried from inspector, follow the documentation but failed


Solution

  • It looks the new version of appium version changed its function signature

    Try this:

    from appium.options.android import UiAutomator2Options
    
    class TestAppium(unittest.TestCase):
        def setUp(self) -> None:
            options = UiAutomator2Options()
            options.load_capabilities(capabilities)
            self.driver = webdriver.Remote(appium_server_url, options=options)