![](https://mobikul.com/wp-content/uploads/2023/10/appium-server-start.png)
Start Appium 2.x server is achievable through manual execution via the command line or automated setup using Java code.
You may also check our Flutter app development services.
Here are the steps for both manual and programmatic server start using Java:
Manual Start of Appium Server in Java:
- Install Node.js: Ensure that Node.js is present on your system by downloading it from the official website if it’s not already installed.
- Install Appium: Install Appium globally using npm (Node Package Manager) by running the following command in your terminal or command prompt:
1 |
npm install -g appium |
- Start the Appium Server: To initiate the Appium server manually, execute the following command:
1 |
appium |
This will launch the Appium server with default settings (listening on localhost, port 4723).
Programmatic Start of Appium Server in Java:
To launch the Appium server programmatically in Java, you can use the Appium Java client library to interact with the server. Below are the steps:
- Add Appium Java Client as a Dependency: Integrate the Appium Java client library into your Java project by including the following Maven dependency within your project’s pom.xml file:
1 2 3 4 5 |
<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>9.0.0</version> </dependency> |
- Start the Appium Server Programmatically: Here’s an example of how to programmatically launch the Appium server in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import java.io.File; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; public class StartAppiumServer { public static void main(String[] args) { // Set the main.js file String mainJSPath = "/path/to/main"; // Path to main.js file // Create an AppiumServiceBuilder instance and build the AppiumDriverLocalService AppiumDriverLocalService service = new AppiumServiceBuilder() .withAppiumJS(new File(mainJSPath)) .withIPAddress("0.0.0.0") .usingPort(4723) // Specify the port you want to use .build(); // Start the Appium server service.start(); // Ensure the server is running if (service.isRunning()) { System.out.println("Appium server started successfully."); } else { System.err.println("Error: Appium server failed to start."); } // Your Appium test code goes here... // Stop the Appium server when done service.stop(); } } |
Replace "/path/to/main"
with the actual paths to the main.js file on your system.
The main.js
file in your Appium project that is used to start the Appium server, it likely serves as an entry point for launching and configuring the Appium server.
When employing the Java client library, the Appium server typically runs on the default IP address “127.0.0.1” (which is the loopback address, referring to the local machine) and the default port “4723”.
Kindly review the code’s output:
These are the default values for the Appium server if you do not specify an alternative IP address or port in your code or configuration.
This Java code creates an AppiumServiceBuilder
with the paths to Node.js and Appium.js and subsequently launch the Appium server via the AppiumDriverLocalService.
Wrap-up:
By following the steps above, you can launch the Appium 2.x server programmatically in Java and employ it for the automated testing of mobile applications.
Please note that the paths and configurations might differ depending on your operating system and the specifics of your Appium installation.
“Automation is not a replacement for manual testing; it’s a complement. They work best together.” – Karl Wiegers
You can read more interesting blogs by Mobikul