Let’s understand How the Architecture of Appium Works
Appium is basically an HTTP server. This server is written in Node.js and it helps to create multiple web Driver session against different platforms. This Appium server receives request from java client which listens for commands from Appium Server.
Let’s have a look at Appium in detail with this video representation.
The way of working of Appium server is almost the same as in selenium RC. The way iOS and android interact with server is quite different. In case of Ios, an Appium proxy commands to a UIAutomation Script. This script would be running in MAC environment.
This application in Ios is called Instruments. In case of android almost everything is same where the server proxy commands to a UIAutomator test case. UIAutomator is a native UI Automation framework which supports junit test cases.
Now let us look at the command line way in which you can install Appium Server on your windows machine.
Installing Appium Server and Node on Windows
Mentioned below is a step-by-step guide on how to install Appium Server and Node on a Windows machine using the command line:
Step #1: Install Node.js
- Open a command prompt by pressing Win + R, typing cmd, and pressing Enter.
- Check if Node.js is already installed by running the following commands:
- Node -v npm -v
- If Node.js is not installed, download the latest version from the official website and follow the installation instructions.
Step #2: Install Appium Server
- Open the command prompt and install Appium globally using npm:
- npm install -g appium
- Verify the installation by checking the Appium version:
appium -v
Step #3: Install Appium Dependencies for Android
If you plan to automate Android applications, you must install Appium dependencies for Android. Follow these steps:
- Install the Android SDK:
- Download Android Studio from the official website.
- Run the installer and follow the on-screen instructions.
- Open Android Studio, go to “Configure” > “SDK Manager,” and install the necessary SDK components.
- Set the ANDROID_HOME environment variable:
- Open the System Properties window by right-clicking on “This PC” or “Computer” and selecting “Properties.”
- Click on “Advanced System settings” > “Environment Variables.”
- Add a new system variable named ANDROID_HOME and the path to the Android SDK as the variable value.
Add Android tools to the system PATH:
- Edit the Path variable in the System Variables section and add the following paths:
perlCopy code
%ANDROID_HOME%\platform-tools %ANDROID_HOME%\tools %ANDROID_HOME%\tools\bin
Step #4: Install Appium Dependencies for iOS (Mac only)
If you plan to automate iOS applications, you must install Appium dependencies for iOS. Follow these steps:
- Install Xcode from the Mac App Store.
- Install Appium dependencies using npm:
npm install -g appium-doctor
- Run appium-doctor to check for any missing dependencies:
Follow the instructions provided by Appium-doctor to install any missing dependencies.
Step #5: Start Appium Server
- Open a command prompt and start the Appium server:
- Appium will start, and you’ll see logs indicating that the server is listening on a specific address and port.
Note: If you encounter any issues related to ports being in use, you can specify a different port using the –port option:
bashCopy code
appium –port 4725
Step 6: Test Appium Installation
After installing Appium successfully, it is time to test the installation by running a simple test script. Create a new file with a .js extension (e.g., test.js) and add the following code:
const wdio = require(‘webdriverio’); const opts = { port: 4723, capabilities: { platformName: ‘Android’, platformVersion: ‘YOUR_ANDROID_VERSION’, deviceName: ‘YOUR_DEVICE_NAME’, app: ‘PATH_TO_YOUR_APK’, automationName: ‘UiAutomator2’, }, }; const driver = wdio.remote(opts); (async () => { await driver.init(); const field = await driver.$(‘ID_OR_XPATH_OF_AN_ELEMENT’); await field.setValue(‘Hello, Appium!’); await driver.deleteSession(); })();
Replace the placeholder values (YOUR_ANDROID_VERSION, YOUR_DEVICE_NAME, PATH_TO_YOUR_APK, and ID_OR_XPATH_OF_AN_ELEMENT) with appropriate values for your Android device and application.
Run the test script using the following command:
If everything is set up correctly, Appium will launch your application on the specified device, interact with the specified element, and close the session.
Why Appium?
If you are wondering why Appium is a preferred choice for mobile testing, here are some of the common reasons:
- Cross-Platform Compatibility: Appium supports Android and iOS, allowing you to write tests for both platforms using a single codebase.
- Programming Language Agnostic: You can write Appium tests in multiple programming languages, including Java, Python, C#, and more.
- Open Source: Because Appium is open source, a worldwide community of developers is constantly improving it. This ensures that it stays up-to-date with the latest mobile technologies.
- No App Modification: Appium tests your app in the same way that users use it, without modifying the app. This provides a more realistic testing environment.
Prerequisites of Installing Appium
Before installing Appium, make sure you have the following prerequisites:
- Java Development Kit (JDK): Appium is built on Java, so you must install the JDK on your machine. You can download the latest JDK version from the official Oracle website.
- Android Studio: If you plan to automate Android applications, install Android Studio to set up the necessary Android dependencies. Download Android Studio from the official website.
- Xcode: For automating iOS applications, you’ll need Xcode. Install it from the Mac App Store if you’re using a Mac.
- Node.js: Appium is built on Node.js, so you need to have Node.js installed. Download the latest version from the official Node.js website.
Conclusion
Hence, now you got to know that installation of Appium is damn easy with the command line rather than doing it manually. NPM is a wonderful package installer and makes your task easier. Install it and start the automation. All the best!!
FAQs
Why is Appium important in iOS and Android App testing? Is it because of its architecture?
Appium plays a pivotal role in iOS and Android app testing, primarily due to its unique architecture, which allows for seamless cross-platform testing.
This tool operates on a client-server model, enabling testers to write tests in their preferred language using standard APIs. Its significance lies in the ability to test native, hybrid, and mobile web apps without needing to alter the app code.
By supporting Android and iOS platforms, Appium facilitates a more efficient testing process, reducing the time and resources spent on writing and maintaining separate tests for each platform.
This approach not only enhances productivity but also ensures consistency in testing across different environments.
How Appium Architecture Works?
Test Script Initialization:
- The developer writes a test script using their preferred programming language and the corresponding Appium client library.
Appium Server Startup:
- The developer starts the Appium Server, specifying the desired capabilities such as the platform (Android or iOS), device details, application path, and other relevant configurations.
Connection Establishment:
- The Appium client library in the test script initiates a connection to the Appium Server by providing the server’s address (IP and port) and the desired capabilities for the test session.
WebDriver Commands:
- The test script, through the Appium client, sends WebDriver commands to the Appium Server. These commands include actions like tapping on an element, entering text, or navigating between screens.
Translation and Execution:
- The Appium Server translates the WebDriver commands into corresponding actions supported by the mobile platform. For example, a WebDriver “click” command might translate to a tap on the screen.
Interaction with Mobile Device:
- The translated commands are then executed on the mobile device, interacting with the application just as a user would. This interaction includes gestures, input, and navigation.
Response Handling:
- The Appium Server captures the responses from the mobile device and communicates them back to the Appium client. These responses may include success or failure indicators, as well as any relevant data.
Test Script Completion:
- The test script processes the responses received from the Appium Server, making decisions based on the success or failure of each command. The script may also include assertions to verify the expected behavior of the application.
Session Closure:
- Once the test script completes its execution, the Appium Server closes the WebDriver session, releasing the resources associated with the test session.
How To Start the Appium server in CMD?
To start the Appium server via the Command Prompt (CMD) on Windows or Terminal on macOS/Linux, you first need to have Appium installed. If you haven’t installed Appium, you can install it using Node.js’s package manager (npm) with the following command:
npm install -g appium
Once Appium is installed, you can start the server by opening CMD or Terminal and running the following command:
appium
This command starts the Appium server with the default settings, typically listening on port 4723. If you want to specify a different port or customize other settings, you can use various flags. For example, to start the Appium server on port 5000, you can use:
appium -p 5000
For more advanced configurations and options, you can refer to the official Appium documentation or use the appium --help
command to see a list of all available command-line options.
Is node js mandatory for Appium?
How do I run an Appium server?
To run an Appium server, follow these simple steps:
- Open your command prompt or terminal.
- Type
appium
and press Enter.
This command starts the Appium server with default settings. You can customize its behavior using various flags (e.g., appium --port 4723
to specify a different port).