This is a complete, start to finish Appium Test. Step 1 starts the appium server, step 6 shuts it down.
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class startUpTest {
private static AppiumDriverLocalService service;
private static AndroidDriver driver;
private static DesiredCapabilities dc;
public static void main(String[] args) throws IOException, InterruptedException {
stepOne();
stepTwo();
stepThree();
stepFour();
stepFive();
stepSix();
}
//Start the Appium Server
private static void stepOne() {
service = AppiumDriverLocalService.buildDefaultService();
service.start();
}
//Define your desired capabilities
private static void stepTwo() {
dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "SAMSUNG_Android");
dc.setCapability(MobileCapabilityType.UDID, "0123456789nc88hh");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
dc.setCapability(MobileCapabilityType.APP, "com.something.yellow");
dc.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.something.yellow.app_launch.activities.LaunchActivity");
dc.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "300");
}
//Initiate your driver
private static void stepThree() throws MalformedURLException{
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), dc);
}
//Run your tests
private static void stepFour() throws InterruptedException{
//Run test
Thread.sleep(10000);
}
//Quit your driver
private static void stepFive() {
driver.quit();
}
//Stop the Appium server
private static void stepSix() {
service.stop();
}
}