Appium 脚本代码中启动appium server

import io.appium.java_client.android.AndroidDriver;
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 org.openqa.selenium.remote.DesiredCapabilities;



public class Test222 {
    public static void main(String[] args) {

        AppiumServiceBuilder builder =
                new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                        .withIPAddress("127.0.0.1")  
                        .usingPort(8000);

        AppiumDriverLocalService service = AppiumDriverLocalService.buildService(builder);
        service.start();


    if (service == null || !service.isRunning()){
      throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
    }



        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "Y9K0214B13002052");
        caps.setCapability("deviceOrientation", "portrait");

        caps.setCapability("platformVersion", "5.1");
        caps.setCapability("platformName", "Android");
        caps.setCapability("appActivity", ".ui.LauncherUI");
        caps.setCapability("appPackage", "com.tencent.mm");
        AndroidDriver  driver = new AndroidDriver(service.getUrl(), caps);


    }
}

示例中 先启动appium server 后启动微信

posted @ 2018-01-02 15:07  testway  阅读(1967)  评论(0编辑  收藏  举报