This is a sample project just to ilustrate how a multiplatform mobile test framework could look like to preserve the same code base for running tests against iOS or Android platforms.
The idea behind the abstraction is the initial information of which platform should we use. If no platform is informed, we should use Android as default.
-
Node.js run time
-
Python 3.12+
-
All the environment set up for Appium solutions
- Install Android Studio
- Install Appium:
npm install -g appiumThis is the appium server - Install UIAutomator2:
appium driver install uiautomator2. The platform specific driver - Set JAVA_HOME and ANDROID_HOME to $PATH
-
Non mandatory, but helpful
- Install Appium Inspector: Useful to inspect the app to find elements locators
- Install Appium doctor: Useful to check environment dependencies
for more info on setting up environment for mobile test automation using Appium, check:
- https://nshthshah.medium.com/appium-tutorial-step-by-step-android-automation-97b84de2fc55
- https://appium.io/docs/en/2.1/quickstart/
- https://www.freecodecamp.org/news/how-to-download-and-install-xcode/
- https://courtneyzhan.medium.com/set-up-appium-2-to-run-xcuitest-for-ios-d4fb557403f
- https://github.com/appium/python-client/blob/master/README.md
- Pytest: To support all test management
- Dotenv: To support the use of
.envfiles - Appium Client: the API to interact with the app through drivers like
UIAutomator2orXCUITest
- Clone the repo and cd to the folder
- Set python environment:
python3 -m venv .venv - Activate python environment:
source .venv/bin/active - Install dependencies:
python3 -m pip install -r requirements.txt - Create
appfolder on the root of the project- Download Android and iOS releases
- To use the iOS version unzip it on the app folder
- Spin up Emulator/Simulator
core package is responsible for the driver management. The main idea is abstract the driver instatiation to provide a single interface to be used throught the code.
DriverFactory- Responsible to manage which specific driver is going to be instantiated according to the
PLATFORMenvironment variable - Make sure we have only one instance available (Singleton)
- Tests should only call this Class to manage drivers
- Responsible to manage which specific driver is going to be instantiated according to the
AndroidDriverandIOSDriverare the specific drivers that interface withAppium Driver(or the Mocked version) binding the desired capabilities for each platformMockAppiumDriveris just a dummy class to mock actual Appium/Selenium drivers
test_driverfactory.pyis the test filehooks.pyis a file to manage hooks used on the testsconftest.pyis a special pytest file to glue any file to the tests
In order to run the tests, we need to pass the value for PLATFORM environment variable. Currently this project supports Android and iOS values.
Important
Make sure your environment is good to go for both Android and iOS
There are 2 basic ways to set this variable value:
To use env file you will need to rename .env_sample file to .env and set PLATFORM variable with the expected value.
PLATFORM=Android
or
PLATFORM=iOS
after setting up .env file, go to the command line and run:
$ pytest -s
WARNING: According to python-dotenv library docs, as we use load_dotenv(override=False) the precedence of environment variables value will be:
- Value of that variable in the environment.
- Value of that variable in the .env file.
- Default value, if provided.
- Empty string.
Here we inform the value for PLATFORM straight on the command line, as it follows:
$ PLATFORM=iOS pytest -s
or
$ PLATFORM=Android pytest -s