1

I'm trying to set up appium test headless with java:

public void startAppiumServer() throws IOException, InterruptedException {

//        Process process;
    String APPIUMSERVERSTARTCMD = "cmd /c " + "\"C:/Program Files (x86)/Appium/node.exe\" " +
            "\"C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js\" " +
            "--address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 " +
            "--selendroid-port 8082 --no-reset --local-timezone --log G:/log_appium.txt";

    Runtime rt = Runtime.getRuntime();
    Log.debug("Send command : " + APPIUMSERVERSTARTCMD);
    final Process pr = rt.exec(APPIUMSERVERSTARTCMD);

    new Thread(new Runnable() {
        public void run() {
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line = null;

            try {
                while ((line = input.readLine()) != null)
                    System.out.println(line);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();

    pr.waitFor();
}

But the appium app did not launch. if i except "cmd /c ", appium will run successfully. But the test just run appium, don't do something else. I want to run my test case after appium launched.

   @BeforeSuite
public void initAndroidTest() throws IOException, InterruptedException {

    LaunchAppium launchAppium = new LaunchAppium();
    launchAppium.startAppiumServer();

    try {

        AppiumRemote remote = new AppiumRemote(driver);

        driver = remote.remoteDevice();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        homePage = CommonFlow.goToMainPage(driver);

    }catch (Exception ex){

    }
}

public static AndroidDriver getDriver() { return driver; }

@Test
public void runLogin(){
    LoginTester login = new LoginTester();
    login.runTest(driver, homePage);
}

Please help me to solve this problem. Thanks

1
  • I'm voting to close this question as off-topic because it is an Appin support request. Please look to the Appium project for support. Jan 20 '16 at 4:22
0
public void startAppium()throws Exception
{
    String command = "appium --session-override -p "+port+" --chromedriver-port "+chromePort+" -bp "+bootstrapPort;

    String output = runCommand(command);

    if(output.contains("not"))
    {
        System.out.println("\nAppium is not installed");
        System.exit(0);
    }
}

public String runCommand(String command) throws InterruptedException, IOException
{
    p = Runtime.getRuntime().exec(command);

    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line="";
    String allLine="";

    while((line=r.readLine()) != null){
        allLine=allLine+""+line+"\n";
        if(line.contains("Console LogLevel: debug"))
            break;
    }
    return allLine;
}

This should start appium server. And if you set appium path in your PATH variable then you don't have to pass full appium path. Just call startAppium() in your test class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.