@Zuzeac I am using Serenity-BDD+Cucumber+Appium for the project. Here i have a library function which starts appium. Then instantiate this in @Beforeclass (JUNIT annotation) or you can do it @BeforeSuite in case of TestNG.
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;
import static io.appium.java_client.service.local.AppiumDriverLocalService.buildService;
import java.io.File;
public final class AppiumServer {
private final static AppiumDriverLocalService service;
static {
service = buildService(new AppiumServiceBuilder()
.withIPAddress("127.0.0.1")
.usingPort(Integer.parseInt("4723"))
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withArgument(GeneralServerFlag.LOG_LEVEL, "info"));
}
public static void startAppiumServer() {
try{
service.start();
}catch(Exception e){
e.printStackTrace();
}
}
public static void stopAppiumServer() {
try{
if (service.isRunning()) {
service.stop();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
Use it as below:
public class RegressionTest {
@BeforeClass
public static void setUp() throws IOException, Exception {
startAppiumServer();
}
@AfterClass
public static void tearDown() throws IOException {
stopAppiumServer();
}
}