Skip to content

Unable to run Appium server programmatically  #252

Closed

Description

@saikrishna321

@TikhomirovSergey as you suggested in the previous post i have my node set in Mac OSX path

➜ AppiumParallel git:(master) ✗ node --version
v0.12.7

echo $PATH
/Users/saikrisv/Library/Android/sdk/platform-tools:/Users/saikrisv/Library/Android/sdk/tools:/Users/saikrisv/Library/Android/sdk/platform-tools:/Users/saikrisv/Library/Android/sdk/tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I able to run node command from any path from ma commandline. Below is the code i use to start the server

AppiumServiceBuilder builder = new AppiumServiceBuilder().withAppiumJS(new File("/usr/local/lib/node_modules/appium/bin/appium.js"))
.withArgument(GeneralServerFlag.APP,
System.getProperty("user.dir") + "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/build/wordpress.apk")
.withArgument(GeneralServerFlag.LOG_LEVEL, "info").usingAnyFreePort(); /and so on/;
AppiumDriverLocalService service = builder.build();
service.start();

Error :::

io.appium.java_client.service.local.InvalidNodeJSInstance: Node.js is not installed
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:87)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)
at com.appium.android.test.AndriodTest.setUp(AndriodTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.io.IOException: Cannot run program "node": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:83)
... 27 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 31 more

java.lang.NullPointerException
at com.appium.android.test.AndriodTest.tearDown(AndriodTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Activity

  1. TikhomirovSergey commented on Oct 1, 2015

    @TikhomirovSergey
    Contributor

    Hi @saikrishna321
    There is really interesting situation

    Are you starting it from the Eclipse for Mac OS?

    This code works when I start it from IntelijIDEA/Eclipse for Windows (7&8). When I do the same from IntelijIDEA/Eclipse for Mac OS X it works with IntelijIDEA (I use v14.x).

    info: Welcome to Appium v1.4.10 (REV c97e824665ae82df682a0b540b38dfe8c13c8ac7)
    info: Appium REST http interface listener started on 0.0.0.0:4723
    info: Console LogLevel: debug
    info: --> GET /wd/hub/status {}
    info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.10","revision":"c97e824665ae82df682a0b540b38dfe8c13c8ac7"}}}
    info: <-- GET /wd/hub/status 200 66.505 ms - 105 {"status":0,"value":{"build":{"version":"1.4.10","revision":"c97e824665ae82df682a0b540b38dfe8c13c8ac7"}}}
    info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"..../sample-code/sample-code/examples/java/junit/../../../apps/ApiDemos/bin/ApiDemos-debug.apk","platformName":"Android","deviceName":"Android Emulator"}}
    info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
    info: [debug] No appActivity desired capability or server param. Parsing from apk.
    info: [debug] No appPackage desired capability or server param. Parsing from apk.
    info: [debug] Using local app from desired caps: /Users/admin/Desktop/appium/sample-code/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk
    info: [debug] Creating new appium session ec0905b7-14a5-4d75-8ba2-697cd1e7df70
    info: Starting android appium

    With Eclipse for Mac OS I catch the same exception (!!!).

    So I have two concerns:

    • the first is there is a bug of java_client. So we have to get it fixed.
    • the second is there is a bug of Eclipse for Mac OS. With the Eclipse for Windows it works (!!!). Maybe there are some settings that should be defined.

    @saikrishna321 If you know which settings should be defined please post them here. Also I recommend you to use IntelijIDEA till the root cause is found or use the following method:

    service.withDriverExecutable

    Anyway everything should work with Maven started from a command line.

  2. TikhomirovSergey commented on Oct 3, 2015

    @TikhomirovSergey
    Contributor

    It is the problem of Eclipse for Mac OS. As soon as possible I'll post the way to resolve the problem

  3. TikhomirovSergey commented on Oct 4, 2015

    @TikhomirovSergey
    Contributor

    @saikrishna321
    So
    As I've mentioned it is the problem of Eclipse IDE (for Mac OS, it is probably for Linux too). Links:

    ... and tons of information that Google can find.

    Actually I've tried some of these solutions:

    1. These fails

    1

    1. Then I made a simple configuration

    1

    This value was copied from output of

    echo $PATH

    1. Then it started to work

    1

    The same works with this samples.

    1

    So I can advice you a few ways to resolve your problem with the test debugging:

    1. To configure Eclipse IDE/current project workspace properly

    2. To use IntellijIDEA instead of Eclipse

    3. To not do something special and set a full path to the certain Node.js instance

      service.withDriverExecutable

    @saikrishna321 I'm waiting for your response. If you are agree then I'll close this ticket. Please provide some more details or describe your ideas otherwise.

  4. saikrishna321 commented on Oct 5, 2015

    @saikrishna321
    MemberAuthor

    @TikhomirovSergey Thanks a lot for all the details and helping me out resolve this issue.

    1. Setting ANDROID_HOME and PATH into Eclipse environment, helped me debug the code.
    2. Running the code from Intellij, had no issues.

    Is possible to set different bootstrap-port, the way we set appium_port ?

    new AppiumServiceBuilder().
    usingPort(4000);

  5. TikhomirovSergey commented on Oct 5, 2015

    @TikhomirovSergey
    Contributor

    @saikrishna321 Yep

    new AppiumServiceBuilder().
    withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,"Your port number");

    Then I'll close this issue. Actually I haven't known about this special thing of Eclipse IDE too :). Thanks! This ticket is marked by lables and information won't be lost.

  6. pr4bh4sh commented on Oct 6, 2015

    @pr4bh4sh

    The issue is marked closed now however i have the solution which works perfectly for me without using any configuration in eclipse at all.
    I have cooked something using the below link prior to the autolaunch introduced in Java client itself.
    http://stackoverflow.com/questions/20922600/execute-adb-command-from-java-program

    public class Utils {
        private static final String[] WIN_RUNTIME = { "cmd.exe", "/C" };
        private static final String[] OS_LINUX_RUNTIME = { "/bin/bash", "-l", "-c" };
    
        private Utils() {
        }
    
        private static <T> T[] concat(T[] first, T[] second) {
            T[] result = Arrays.copyOf(first, first.length + second.length);
            System.arraycopy(second, 0, result, first.length, second.length);
            return result;
        }
    
        public static List<String> runProcess(boolean isWin, String... command) {
            System.out.print("command to run: ");
            for (String s : command) {
                System.out.print(s);
            }
            System.out.print("\n");
            String[] allCommand = null;
            try {
                if (isWin) {
                    allCommand = concat(WIN_RUNTIME, command);
                } else {
                    allCommand = concat(OS_LINUX_RUNTIME, command);
                }
                ProcessBuilder pb = new ProcessBuilder(allCommand);
                pb.redirectErrorStream(true);
                Process p = pb.start();
                p.waitFor();
                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String _temp = null;
                List<String> line = new ArrayList<String>();
                while ((_temp = in.readLine()) != null) {
                    System.out.println("temp line: " + _temp);
                    line.add(_temp);
                }
                System.out.println("result after command: " + line);
                return line;
    
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }

    @TikhomirovSergey it would be time saver if this could be integrated with java client.

  7. TikhomirovSergey commented on Oct 7, 2015

    @TikhomirovSergey
    Contributor

    @pr4bh4sh
    Thanks! I'll try this. If everithing is fine I'll propose a fix.

  8. saikrishna321 commented on Oct 8, 2015

    @saikrishna321
    MemberAuthor

    @TikhomirovSergey to trigger the test in parallel i must pass the android device serial as well UDID.

    How can i pass this ?

  9. saikrishna321 commented on Oct 8, 2015

    @saikrishna321
    MemberAuthor

    Right now i'm running the parallel tests by using GNU Parallel

    https://github.com/saikrishna321/AppiumAndroidParallelExecution

  10. TikhomirovSergey commented on Oct 8, 2015

    @TikhomirovSergey
    Contributor

    @saikrishna321
    It will be cool if you open one more issue with the detailed description. If you have any problem with it please open a new one. Today or tomorrow I'm going to propose the fix of this issue.

  11. saikrishna321 commented on Oct 8, 2015

    @saikrishna321
    MemberAuthor

    @TikhomirovSergey awesome .. i will do that.. closing this ticket

  12. added a commit that references this issue on Oct 16, 2015
  13. Paul-Oginni commented on Dec 8, 2015

    @Paul-Oginni

    It worked for me when I added the PATH variable the way TikhomirovSergey demonstrated in his screenshots.

  14. anuja1111 commented on Jan 31, 2016

    @anuja1111

    Hi,

    I have posted detailed explanation on starting and stopping Appium server with java code which works in windows as well as in Linux.
    http://qaautomated.blogspot.in/2016/01/how-to-start-appium-server-using-java.html

    Regards,
    Anuja

  15. jeangb commented on Feb 14, 2017

    @jeangb

    @anuja1111 Thank you I've tried your java class and it works with success.
    However, I still have the Eclipse bug meaning if I don't set PATH into Eclipse environment, my test won't be able to run on my device.
    By the way, do you think it's possible to display the appium server logs elsewhere than the console in Eclipse ? For example in an other view ?
    Best regards

  16. FlexShamil commented on Jan 16, 2018

    @FlexShamil

    Hello guys, I am testing chrome with my app, so as I enter email and password I get keyboard pulled up and I am unable to use pressKeyCode ENTER its just goes red. thats on 1.7.1 version for appium. per appium.io documentations those methods are supposed to be workable.

    is there a solution to that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions