Implement shell commands

I would like to implement a function which does the steps below :

Download content from the server using this command :
node ~/Desktop/plugins-dist-1/app/package --config appconfig.js --targetDir package/app --host myhost --port 8888 --https --username myuser --password mypass --force

Create the package for the upload using this command :
node ~/Desktop/plugins-dist-1/app/package --config appconfig.js --targetDir package/app --CouldPoxy myproxy --CloudUser myuser --CloudPassword mypass createpackage

Upload the package to the cloud…
Start the build on the cloud …
Check the status until the build is not finished …
Download the result …

Instead of doing this manually in the shell, I would implement a @test function do it.

I need a way how to implement this, I am using appium 1.4, android, Junit.

Thank you

@foudelsalhi

I created 2 methods to handle Download/Upload

Please give a try:

public void downloadFile() {

    CommandLine command = new CommandLine("node");
    command.addArgument("~/Desktop/plugins-dist-1/app/package");
    command.addArgument("--config");
    command.addArgument("--appconfig.js");
    command.addArgument("--targetDir");
    command.addArgument("package/app");
    command.addArgument("--host");
    command.addArgument("myhost");
    command.addArgument("--port");
    command.addArgument("8888");
    command.addArgument("--https");
    command.addArgument("--username");
    command.addArgument("--password");
    command.addArgument("mypass");
    command.addArgument("--force");

    try {
        DefaultExecutor exec = new DefaultExecutor();
        exec.execute(command);

    } catch (ExecuteException e) {
        e.printStackTrace();
    } catch (IOException ioE) {
        ioE.printStackTrace();
    }
}

public void uploadFile() {
    CommandLine command = new CommandLine("node");
    command.addArgument("~/Desktop/plugins-dist-1/app/package");
    command.addArgument("--config");
    command.addArgument("--appconfig.js");
    command.addArgument("--targetDir");
    command.addArgument("package/app");
    command.addArgument("--CouldPoxy");
    command.addArgument("myproxy");
    command.addArgument("--CloudUser");
    command.addArgument("myuser");
    command.addArgument("--CloudPassword");
    command.addArgument("mypass");
    command.addArgument("createpackage");

    try {
        DefaultExecutor exec = new DefaultExecutor();
        exec.execute(command);

    } catch (ExecuteException e) {
        e.printStackTrace();
    } catch (IOException ioE) {
        ioE.printStackTrace();
    }
}

Please import common-exec lib.
You can download from:
https://commons.apache.org/proper/commons-exec/download_exec.cgi

1 Like

Thank you I will try it and if there something I will share it here .

@foudelsalhi1988
Oops, I think it should be:

CommandLine command = new CommandLine("/usr/local/node");

Please give a try. Hopefully that can help you.

1 Like

I m using windows :smile:

So try to get the [Node] location. On my windows, it’s: C:/Program Files (x86)/Appium/node

And the new code should be uodated with :
CommandLine command = new CommandLine(“C:/Program Files (x86)/Appium/node”);

1 Like

What about if I want to put the path in general I mean if you are using windows it gets the nodes location automatically if you are using Linux OS the same ? :grinning:

And what you mean by import common-exec : you mean in eclipse or what

If you can type [node] to open node.js directy, it’s possible to remove the path before [node] in above code.

I have just tried to add Node location in Variables system on Windows and I got a successful result without the Node’s path.

So if you are going to use it on Linux OS or somewhere else, you can add the path for Node

About common-exec. Yes, in eclipse

1 Like

You re genius :smile: