Updated 18 October 2023
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:
1 |
npm install -g appium |
1 |
appium |
This will launch the Appium server with default settings (listening on localhost, port 4723).
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:
1 2 3 4 5 |
<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>9.0.0</version> </dependency> |
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.
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
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.