Launching and stopping appium server programmtically


#122

@Hassan_Radi…I am trying to launch appium automatically using Javascript…but could not do it

My code is below

“use strict”;

require("…/helpers/setup");

var wd = require(“wd”),
_ = require(‘underscore’),
serverConfigs = require(’…/helpers/appium-servers’),
localServer = require(’…/helpers/local-server’); //new

var uTests = require("…/dal/tests").list;
var serverHost = require("…/dal/tests").serverHost;

//describe(“Android Chrome browser”, function () {
describe(“android local server”, function () {
this.timeout(900000);
var driver;
var allPassed = true;

before(function () {

localServer.start();

var serverConfig = serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("…/helpers/logging").configure(driver);

var desired = _.clone(require("../helpers/caps").android19);
desired.browserName = 'Chrome';

return driver.init(desired);

});

after(function () {
localServer.stop();
return driver
.quit();
});

As on internet I can find all the help related to Java…no javascrpt…


#123

@psingh
What error message does it show to you?? please include your appium log to help better understand the problem.


#124

Right now My code for running my test is

Chrometest.js:

“use strict”;

require("…/helpers/setup");

var wd = require(“wd”),
_ = require(‘underscore’),
serverConfigs = require(’…/helpers/appium-servers’),
appium = require(’…/node_modules/appium/lib/server/main.js’),
parser = require(’…/node_modules/appium/lib/server/parser.js’);

var uTests = require("…/dal/tests").list; // in this there is list of test which gets executed
var serverHost = require("…/dal/tests").serverHost;

//var args = parser().parseArgs();

describe(“Android Chrome browser”, function () {

this.timeout(900000);
var driver;
var allPassed = true;

before(function () {

appium.run(args, function () { /* console.log(‘Rock and roll.’.grey); */ });

var serverConfig = serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("…/helpers/logging").configure(driver);

var desired = _.clone(require("../helpers/caps").android19);
desired.browserName = 'Chrome';

return driver.init(desired);

});

after(function () {
return driver
.quit();
});

I am running this piece of code using command - mocha chrometest.js
I am trying to run appium in before function


#125

@Hassan_Radi I think …I am not able to correctly understand …what to include in my code to start appium server


#126

@psingh
Currently the only possible ways to start the server are:

  • Manually before you run your script from Appium GUI application.
  • Automatically using your language binding. Currently this feature is supported by java client v3.2.0 only (as far as I know).
  • The last solution is to write your own code that starts the server using your preferred language.

#127

Ok …I was trying for third option to write a javascript code to start the server…


#128

I was referring to appium.js file …to see how they wrote there…but till now no success


#129

@psingh
To start the server you just need to start a new nodejs process and pass the appium.js file to it and that’s it (You might also want to pass cusotm server arguments in case you need that).


#130

@Hassan_Radi…Thats what I am trying to first start node and then run appium.js…but couldnt figure out how to do that in javascript…how to execute a command to run it…


#131

@psingh
Sorry my knowledge of JavaScript is kinda limited, but you can give this a try or Google for more help about that :frowning:.


#132

@Hassan_Radi…Anyways thanks a lot…will find a way…


#133

Hello All,

Please check the below link from my blog, hope it will help you. Thanks!

Regards,
A. K. Sahu


#134

Hi All,

Please check the below link from my blog, hope it will help you. Thanks!

Regards,
A. K. Sahu


#135

Hi All,

Is there any way to start and stop appium server on a remote machine programmatically? I have a server machine where all the devices are connected with Appium Setup. We are doing a feasibility study to perform parallel execution without using GRID and so it is required to start different instances of appium server on various ports on the remote machine. We have done the feasibility on our local machines, but looking for a way to start appium server on remote machine. Any help on this will be grateful! Thanks.

Note:

We are doing this feasibility on a windows server machine for Android devices


#136

You can try Jenkins. I have used it as a POC but not in real scenario.


#137

Hi pr4bh4sh,

Can you let me know the steps to do it? We are using Jenkins for triggering our test execution. If you could throw some light on how to do it, I can try it out. Thanks.


#138

Hi ,

Mention below the code for running Appium server
Create a .bat file and write this code
@echo on
cd /d E:\Appium\node_modules\appium
E:\Appium\node . -a 127.0.0.1

Before initializing run the batch file.

OR: You can use below code to run the Appium server. This is work with Appium version 1.3.5 and above it has some issue that I am analysing.
public static final void startAppium() throws IOException, InterruptedException {
CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", false);
command.addArgument("–address", false);
command.addArgument(“127.0.0.1”);
command.addArgument("–port", false);
command.addArgument(“4723”);
command.addArgument("–log-level");
command.addArgument(“warn”);
command.addArgument("–session-override",true);
command.addArgument("–local-timezone",true);
command.addArgument("–log-no-colors", true);
command.addArgument("–backend-retries");
command.addArgument(“6”);
//command.addArgument("–force-quit-instruments",true);
//command.addArgument("–log-g /Users/slinger/Desktop/appium.log");
// command.addArgument("–native-instruments-lib",true);
/command.addArgument("–automation-name");
command.addArgument(“Jitu_iPad_Automation”);
/
//command.addArgument("–ignoreUnimportantViews",true);
// command.addArgument("–autoAcceptAlerts",false);
//command.addArgument("–show-ios-log");
//command.addArgument("–full-reset", false);
// command.addArgument("–nativeInstrumentsLib",true);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.execute(command, resultHandler);
Thread.sleep(5000);
System.out.println(“Appium server started”);
}

Regards
Jitu


#139

Down one i am using for mac


#140

You can start appium server as local service
refer following video… same way you can start server on MAC too.


#141

@Hassan_Radi
I used below code to start appium:
‘C:\Program’ is not recognized as an internal or external command,

CommandLine command = new CommandLine(“cmd”);
command.addArgument("/c");
command.addArgument("“C:\Program Files (x86)\Appium\node.exe”");
command.addArgument("“C:\Program Files (x86)\Appium\node_modules\appium\bin\Appium.js”");
command.addArgument("–address");
command.addArgument(“127.0.0.1”);
command.addArgument("–port");
command.addArgument(“4723”);
command.addArgument("–no-reset");
command.addArgument("–session-override");
command.addArgument(“true”);
command.addArgument("–log");
//command.addArgument(“C:/appiumLogs.txt”);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
} catch (ExecuteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

’C:\Program’ is not recognized as an internal or external command,
operable program or batch file.