Appium Environment Set Up

Appium is an open source test automation framework. We use it with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.

Basics installation of Appium mobile test environment follows these steps :

  1. First to install appium we need to have NodeJs installed. If you do not have NodeJs installed in your computer follow the link to download and install latest version of NodeJs on your machine following this link : “https://nodejs.org/” After installation, depending on your machine, you may need to restart your computer to take NodeJs effective on your command line. To verify, you can type “node -version” to see if Node is available.
  2. Then get npm installation package and install on your machine, Type “npm install -g appium” in your command line Terminal on Mac OS and CMD on Windows.
  3. We assume so far you have already installed a Java environment. if not here how to have a Java JDK and Java IDE on your machine :
    1. For JDK : Read the post here.
    2. For IDE : Read the post here.
  4. Install Android Studio : download the latest version of android studio for your machine from “https://developer.android.com/studio” and install. Once installation finished, we can create our first project and in it out first emulated android device. Then we will get the running emulation info to connect our test environment to the machine. Here some screenshots to help the process:
  5. Install Appium-Inspector (This is optinal 3rd party app – which helps alot in locating our test elements) from their github account. “https://github.com/appium/appium-inspector/releases”. Make sure your Appium Inspector is configured to receive your emulated device and location of your test app is defined correctly. See the reference image below.
  6. Run your app in Appium inspector and record your test movements. Then you can copy recorded path movements in your Eclipse Selenium Set Up.
  7. Set your Eclipse Java IDE for a selenium test environment. Create a new Maven Project and edit your pom.xml add properties and dependencies below:
/* <properties>
  	<maven.compiler.source>12</maven.compiler.source>
  	<maven.compiler.target>12</maven.compiler.target>
  </properties>
  <dependencies>
  	<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
	<dependency>
	    <groupId>org.seleniumhq.selenium</groupId>
	    <artifactId>selenium-java</artifactId>
	    <version>3.141.59</version>
	</dependency>
	
	<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
	<dependency>
	    <groupId>io.appium</groupId>
	    <artifactId>java-client</artifactId>
	    <version>7.6.0</version>
	</dependency>
	
		<!-- https://mvnrepository.com/artifact/junit/junit -->
	<dependency>
	    <groupId>junit</groupId>
	    <artifactId>junit</artifactId>
	    <version>4.13.2</version>
	    <scope>test</scope>
	</dependency>
	
	<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
	<dependency>
	    <groupId>org.apache.maven.plugins</groupId>
	    <artifactId>maven-compiler-plugin</artifactId>
	    <version>3.10.0</version>
	</dependency>



  </dependencies>
*/

Then create your firs Mobile Driver as below :

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Base {
	
	public static AndroidDriver<AndroidElement> capabilities() throws MalformedURLException{
		DesiredCapabilities capabilities = new DesiredCapabilities();
		
/*		{
		  "platformName": "android",
		  "appium:app": "C:\\Users\\nesli\\Downloads\\Apium\\ApiDemos-debug.apk",
		  "appium:deviceName": "emulator-5554",
		  "appium:noReset": true,
		  "appium:automationName": "UiAutomator2"
		}
		
*/
		File apk = new File("src/test/resources/ApiDemos-debug.apk");
		System.out.println(apk.getAbsolutePath());
		capabilities.setCapability(MobileCapabilityType.APP, apk.getAbsolutePath());
		capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
		capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
		capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
		
		URL appiumServerUrl=new URL("http://localhost:4723/wd/hub");
		AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(appiumServerUrl, capabilities);
		return driver;
		
	}

}

As you see in the capabilities set, we define the same json info we have seen in tha Appium inspector to connect our work environment to our android emulators.

From this point on you are free to use your new driver and add more test locators and test senarios.

Aix Observer
Aix Observer
Articles: 31

Leave a Reply

Your email address will not be published. Required fields are marked *