Currently I'm using Appium Desktop v1.7.2 and manually starting the server before running the script. But now I have to start Appium server through code/program for v1.7.2 to do framework design. I came to know that Appium Desktop version cannot be started programmatcally(If I'm not wrong).
Anyone can let me know that, Is their Appium v1.7.2 CLI can be download/available? if yes, Any sample script would be great help.
Here is my own Appium server utilities class:
import java.io.IOException;
import java.net.ServerSocket;
import org.openqa.selenium.remote.DesiredCapabilities;
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;
/**
* This class handles Appium Server
*
* @author Bill Hileman
*/
public class AppiumServer {
private AppiumDriverLocalService service;
private AppiumServiceBuilder builder;
private DesiredCapabilities cap;
private int port = 4723;
public void startServer() {
// Set Capabilities
cap = new DesiredCapabilities();
cap.setCapability("noReset", "false");
// Build the Appium service
builder = new AppiumServiceBuilder();
builder.withIPAddress("0.0.0.0");
builder.usingPort(port);
builder.withCapabilities(cap);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");
// Start the server with the builder
service = AppiumDriverLocalService.buildService(builder);
service.start();
}
public void stopServer() {
service.stop();
}
public boolean serverIsRunnning() {
boolean isServerRunning = false;
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
serverSocket.close();
} catch (IOException e) {
// If control comes here, then it means that the port is in use
isServerRunning = true;
} finally {
serverSocket = null;
}
return isServerRunning;
}
}