This comprehensive guide will assist you in setting up your development environment on a fresh PC, including Maven, Java 8, Appium, and the Android SDK for mobile app testing.
Before you begin, ensure that you have the following prerequisites installed on your machine:
-
Java 8: Maven and Appium are compatible with Java 8. Download and install it from the official Oracle website.
-
Maven: Download the latest version from the official Apache Maven website and follow the installation instructions.
-
Node.js: Appium is a Node.js server. Download and install Node.js from the official Node.js website.
-
Appium: After installing Node.js, open a terminal and run the following command to install Appium globally:
npm install -g appium
-
Android SDK: Download and install the Android SDK. You can obtain it as part of Android Studio or separately. Follow the instructions on the official Android developer website to install the SDK.
Set the necessary environment variables after installing Java, Maven, and Android SDK:
-
JAVA_HOME: Set this variable to the installation path of your Java JDK. For example:
export JAVA_HOME=/path/to/your/java/installation -
M2_HOME: Set this variable to the installation path of Maven. For example:
export M2_HOME=/path/to/your/maven/installation -
ANDROID_HOME: Set this variable to the installation path of your Android SDK. For example:
export ANDROID_HOME=/path/to/your/android/sdk -
PATH: Add the following to your PATH environment variable:
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
To ensure that Java, Maven, Appium, and the Android SDK are installed correctly, open a terminal and run the following commands:
-
Java:
java -version
-
Maven:
mvn -version
-
Appium:
appium -v
-
Android SDK:
sdkmanager --version
Open a terminal and run the following commands to install the necessary SDK components:
sdkmanager "platform-tools" "platforms;android-<version>" "emulator" "system-images;android-<version>;google_apis;<version>"Replace <version> with the Android & Google APIs version you want to emulate.
Use the following command to create an AVD with desired specifications:
avdmanager create avd -n <emulator_name> -k "system-images;android-<version>;google_apis;<version>"Replace <emulator_name> with the desired name for your emulator, and <version> with the Android & Google APIs version you want to emulate.
Launch your Android Emulator using the following command:
emulator -avd <emulator_name>Replace <emulator_name> with the name of your configured AVD.
Now you have set up the Android Emulator and are ready to use it for testing with Appium.
-
To run tests locally, open a terminal in project root folder and run:
mvn clean test -DdeviceId={device_or_simulator_id} -DappPath={app_path} -Denv=local -
To run tests on cloud, open a terminal in project root folder and run:
mvn clean test -Denv=cloudNote: app & device are specified in browserstack.yml