1

Steps I am following , to start the server is : Created a bat file with the below command : "C:/Program Files (x86)/Appium/node.exe" "C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js" --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 18 --automation-name Appium --no-reset --local-timezone --log E:\Android\appium.log""

Code Written to start the server :

public class Testing {
    AppiumDriver driver;

    @BeforeTest

    public void AppiumServerStart() throws MalformedURLException, InterruptedException {

        String s = null;

        String Filepath = "C:\\appiumserver.bat";

        // String Command = \""C:/Program Files (x86)/Appium/node.exe"
        // "C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js"
        // --address 127.0.0.1 --port 4723 --platform-name Android
        // --platform-version 18 --automation-name Appium --no-reset
        // --local-timezone"\"

        System.out.println(Filepath);

        try {
            Process p = Runtime.getRuntime().exec(Filepath);


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println(Filepath);
        System.out.println("Server Started");

        Thread.sleep(6000);

}

Code to Add Desire Capabilities and create android driver instance :

public class DemoCalc extends Testing {

    AppiumDriver driver;

    @Test

    public void Setup() throws MalformedURLException, InterruptedException {

        File file = new File(System.getProperty("user.dir"));

        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.VERSION, "4.4.4");
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "169.254.140.101:5555");
        cap.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2");
        cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
        driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);

However , the below exception is thrown on Android driver instance :

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'

If I manually , start the server by clicking on appium.exe ,then issue does not occur. But when the server is started from java code issue appears.

After running the bat file to start the appium server, i see the node process in task manager , which shows the appium server has been connected.

Please help

  • When started by bat file, try this url on browser "http://localhost:4723/wd/hub" (replace localhost and port respectively. If you get not a valid resource, then it would mean appium node server is running. – Shambu Aug 07 '15 at 16:16
  • if i add the local host url , it shows that the appium server is working. Also , if i first run a java code to start a server and then manually , run a selenium code , it works fine . But when i combine this two things together and try to run , it fails with the exception that is given in the description. – Sagar Daine Aug 10 '15 at 04:45

1 Answers1

0

Try to run Appium server as a separate thread before executing the test.

  • I am running a different class to start the server and then i am trying to execute a class which has selenium script . Then also it wont work – Sagar Daine Aug 11 '15 at 16:07
  • Of course it wont work because the server starter executes the start command and after, finishes the start command and starts executing the tests. But then server is no longer there. You need to **run server parallel** the test execution. So just implement server as parallel task ([example](http://stackoverflow.com/questions/11218720/running-a-task-in-parallel-to-another-task)). – Kristaps Mežavilks Aug 12 '15 at 10:59
  • i see the node process in task manager , which shows the appium server has been connected.. Appium server remains active , it doesnot get stop. I – Sagar Daine Aug 24 '15 at 15:38
  • I see the server still running , in cmd even after the server start class finished execution. Which means , server is runs while test is running. – Sagar Daine Aug 24 '15 at 17:44