How to set up and run Appium for android apps with Java client with Emulator setup.
Appium is an open-source automation tool for mobile applications. It is a cross-platform tool that is used to automate native, hybrid, and mobile web applications running on ios, android, and windows platforms. In this tutorial, we are going to set up Appium and run a sample example.
Download the latest version of the Appium desktop App Image from here. Under "Assets" download AppImage for Linux. Go to download directory and open terminal. Give permission for the app image file.
Now, execute the AppImage file either by double-clicking it or running the following command.
In order to set up an Android Emulator, you can set it up via a command-line tool without installing an android studio but here, we are going to download an android studio and set up android SDK to run Emulator. For this download android studio from here. Extract the downloaded tar file.
Go to the extracted directory cd to the bin directory you can see the studio.sh simply execute this sh file by opening the terminal. Which will popup the android studio setting import option. Select "Do not import settings". Click "Next", select "Standard" and verify the setting. Make sure to verify the path of SDK installed.
Add the following line at the end of the file.
You can launch the device on Emulator via the command line so that you don't need to open the android studio each time you run the device. For this, open the terminal use command:
Here, we have two virtual devices installed in your case it will output the list of devices downloaded.
For IntelliJ Idea:
Create a sample class to config the android driver. Here, we are using the sample calculator app to test and the driver setup config looks like below:
Table Of Contents
1. Introduction:
2. prerequisites:
- Installed JDK
- NodeJs
3. Download and run Appium:
chmod a+x
./AppImageYou can see as the Appium Ui started similar to this.
Now, start the Appium server with default port 4723 by clicking the "Start Server" button.
4. Setup Android Emulator:
tar -xvf android-studio.tar.gz
Click "Next" and "Finish" which will download the SDK on the SDK folder mentioned.
Now, we need to configure the android virtual device for this click "Configure" and select "AVD Manager".
If you see "dev/kvm device: permission denied" you can give permission for the user by using the command:
sudo chown yourLinuxUser /dev/kvmCreate a Virtual Device
After that, select the downloaded image and click "Next" and verify android virtual device configuration and click "Finish" to finish the virtual device setup. Now you can launch the virtual device in the Emulator.
Now, let's configure the SDK path in our system. For this open bashrc file by using the command:
sudo gedit ~/.bashrc
export ANDROID_HOME=/home/kchapagain/Downloads/Sdk export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$PATH export PATH=$PATH:$ANDROID_HOME/platform-toolsMake sure you provided the correct download SDK path in "ANDROID_HOME" in my case it's "/home/kchapagain/Downloads/Sdk". Save the file and reload the changes by using the command:
source ~/.bashrc
emulator -list-avdsOutput:
Pixel_2_API_28 Pixel_2_API_28_2
Now, run the device on the Emulator using command:
emulator -avd Pixel_2_API_28User your device name instead "Pixel_2_API_28". It will run the android virtual device on Emulator.
Create a java project and create a package called "libs" under "src". Copy all the downloaded jar file in this package and load the jar file from Ide.
Go to: File >> Project Structure(Ctr + Alt + Shift + s) >> Libraries and click the + icon on the top left corner and select package.
6. Setup driver config for Appium:
@Before public static void setUp() throws MalformedURLException { DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability("platformName", "Android"); cap.setCapability("deviceName", "50b6ab0"); cap.setCapability("appPackage", ""); cap.setCapability("appActivity", ""); cap.setCapability("automationName", "UiAutomator1"); cap.setCapability("autoGrantPermissions", true); cap.setCapability("autoAcceptAlerts", "true"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); }