Hi Katalon Community,
I have a use case where I want to manually start the Appium server from a script in Katalon Studio—similar to how it’s done in a Java-based Appium framework using:
service = AppiumDriverLocalService.buildService(builder);
service.start();
Is there a way to programmatically start the Appium server like this within Katalon Studio? Any suggestions or workarounds would be greatly appreciated!
1 Like
Hi @mandeep.singh1,
Thank you for sharing your issue. As KS doesn’t natively expose a built-in API to programmatically control the Appium server like you would with AppiumDriverLocalService
in pure Java, you can still manually start the Appium server by a custom script with some commands.
You can use Runtime.exec()
or ProcessBuilder
in Groovy (Katalon uses Groovy under the hood) to start Appium from your test case or Test Listener.
Here is sample script to do it manually:
import java.lang.Runtime
def startAppiumServer() {
String command = "appium" // make sure 'appium' is in your system PATH
Process process = Runtime.getRuntime().exec(command)
println "Appium server started."
}
startAppiumServer()
Make sure that Appium is installed globally and accessible via appium
command in your terminal.
If you want to stop the Appium server, you can kill the process, either by PID or using:
"taskkill /F /IM node.exe" // Windows
"killall node" // macOS/Linux
This stops all Node.js processes.
Hope this can help. Thank you
you can manually start/stop the Appium server in Katalon Studio using the Appium Java Client library. Here’s how to implement it:
1. Add Appium Java Client Dependency
- In your Katalon project, go to Project > Settings > Build Tool > Dependencies.
- Add the Appium Java Client (replace
<version>
with the latest version):
xml
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.0.0</version>
</dependency>
2. Create a Utility Class
Create a Groovy class (e.g., AppiumServerManager.groovy
) under Keywords
:
groovy
import io.appium.java_client.service.local.AppiumDriverLocalService
import io.appium.java_client.service.local.AppiumServiceBuilder
import io.appium.java_client.service.local.flags.GeneralServerFlag
class AppiumServerManager {
private static AppiumDriverLocalService service
static void startAppiumServer() {
if (service == null || !service.isRunning()) {
AppiumServiceBuilder builder = new AppiumServiceBuilder()
.withArgument(GeneralServerFlag.LOG_LEVEL, "warn")
.usingPort(4723) // Default Appium port
.withIPAddress("127.0.0.1")
service = AppiumDriverLocalService.buildService(builder)
service.start()
}
}
static void stopAppiumServer() {
if (service != null && service.isRunning()) {
service.stop()
service = null
}
}
}
3. Use in Test Cases
Call the methods in your test script:
groovy
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.AfterTestCase
@BeforeTestCase
def startServer() {
AppiumServerManager.startAppiumServer()
}
@AfterTestCase
def stopServer() {
AppiumServerManager.stopAppiumServer()
}
// Your mobile test steps
Mobile.startApplication('path/to/app.apk', true)
Mobile.tap(findTestObject('LoginButton'), 10)
4. Configure Desired Capabilities
Set capabilities in your Mobile Settings (no need to start the server via Katalon UI):
groovy
// In your test case
import io.appium.java_client.remote.MobileCapabilityType
import org.openqa.selenium.remote.DesiredCapabilities
DesiredCapabilities caps = new DesiredCapabilities()
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android")
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2")
caps.setCapability(MobileCapabilityType.UDID, "emulator-5554")
caps.setCapability(MobileCapabilityType.APP, "path/to/app.apk")
// Start driver with custom server URL
MobileDriver driver = new AndroidDriver(service.getUrl(), caps)
Key Notes
- Port Conflicts: Ensure the port (e.g.,
4723
) is free.
- Logs: Access server logs via
service.getStdOut()
.
- Compatibility: Match the
java-client
version with your Appium server (e.g., Appium 2.x needs java-client
9.x).
Troubleshooting
If you see ClassNotFoundException
, verify the dependency is added correctly in build.gradle or pom.xml. For advanced configurations (e.g., custom IP/log paths), modify the AppiumServiceBuilder
arguments.