Appium installfest

Prenez
4 min readAug 21, 2024

--

pulling it all together to run my first tests

Traveled a long way on a short road today.

When I came in, I was all set to run my first Appium test with all the new bits, or so I thought.

OPENSSL VERSIONS FOR APPIUM CLIENT

The first issue was openSSL. There was a version mismatch, I had the appium-python-client driver installed in Pycharm that wanted to use version 1.1 but python3.09 uses version 2.n. The solution was to pip a downgrade to urllib3, but didn’t seem to work, got the ‘external manager message.’ Turned out the solution was nuanced. I had to pip inside the .venv, the virtual environment, that Python sets up for itself. once I did, that error went away. I asked the Jetbrains AI about it but it missed the part where I had to go into the .venv, the Python project’s virtual environment, that solution came from StackOverflow. Turns out the best way to do that, to run pip inside the .venv, is to open a terminal inside Pycharm, opens right into the virtual environment. pip worked the first time like a ch…like a Pycharm.

Note the solution was NOT to change openSSL version at the system level. AI made all kinds of suggestions to do that. Tsk. Perfect example of AI giving terrible, wrong advice with complete confidence. I did get a good idea for localizing links in the home directory, though. Thanks, AI.

DEPRECATED DESIRED_CAPABILITIES DICT

Then I ran into issues passing in the options in for testing Chrome on an Android device. The course I’m taking is great but it has expected anachronisms — that’s fine, that’s part of the fun. Turns out the parameter that holds the options is no longer a vanilla dict() in Python but an Options class, specific to the platform, so there’s one for iOS, one for Android, one for Selenium and so on. So your code has to create an Options bag with the right driver, then call methods on it to add the params.

WHERE’S ANDROID_HOME?

Another issue was that, although Android_Home has been specified in my .zshrc AND my .zprofile for years now, for some reason the Python run couldn’t find it. For some reason, moving it earlier in the config file solved the problem (.zprofile I think).

LOADING UIAUTOMATOR2 ETC

Another issue I ran into was that the lessons didn’t include instructions on how to load the drivers into appium. You have to list the drivers that are available to appium and then do a driver install for each of them into appium, in my case XCIUTL for iOS and UIAutomator2 for Android.

APPIUM-DOCTOR

I also discovered and ran appium doctor to check the rest of the installation and it checked out. Once I for the Android Home problem fixed, it was perfect. Had another deprecation error on the version of appium-doctor that was recommended, but the install contained hints for finding the right one.

WHEW!

All that to run my first test! Once I’d gotten all this config right, I was good to go. I ran both an iOS test, just a raw one, and an Android test that opened Chrome!

So didn’t get as far as I wanted to but getting these things set up is always the hardest part. I feel great about it. It’s great doing it in a language I don’t know and knocking in two skills at once. I’ve just been through a hard time, personally, couldn’t think clearly for almost four months, was traumatized from relationship problems. But things change, the clouds lift, and the next chapter opens up.

Here’s the test code I got to work. It’s short but brother, it is all in the details. You have to run appium server, your emulator, and pycharm together…hmm, kinda like vs code and Metro for React Native apps. The client-server model.

from appium import webdriver 
from appium.options.ios.xcuitest.base import XCUITestOptions
from appium.options.android.uiautomator2.base import UiAutomator2Options
from appium.options.android.uiautomator2.base import ChromeOptionsOption
import os


desired_capabilities = {
'platformName': 'iOS',
'platformVersion': '17.5',
'deviceName': 'iPhone 15 Pro',
'automationName': 'XCUITest',
}

desiredd_capabilities = {
'platformName': 'Android',
'deviceName': 'Android',
'automationName': 'uiautomator2',
'browserName': 'Chrome',
}

# "app": "/path/to/your/app.apk" # replace with the path to your app
# Ensure Environment Variables are set (for demonstration purposes)
os.environ['ANDROID_HOME'] = os.path.expanduser('~/Library/Android/sdk')
os.environ['ANDROID_SDK_ROOT'] = os.path.expanduser('~/Library/Android/sdk')

desired_caps = {
"platformName": "Android",
"platformVersion": "14", # replace with your Android version
"deviceName": "emulator-5554", # replace with your device name
'automationName': 'uiautomator2',
'browserName': 'Chrome',
}


iosOptions = XCUITestOptions()
iosOptions.load_capabilities(desired_capabilities)

androidOptions = UiAutomator2Options()
androidOptions.load_capabilities(desired_caps)

appium_server_url = 'http://localhost:4723'
#driver = webdriver.Remote(appium_server_url, options=iosOptions)

driver2 = webdriver.Remote(appium_server_url, options=androidOptions)

--

--

Prenez
Prenez

Written by Prenez

Writes iOS apps in Swift and stories in American English.

No responses yet