do you mind me asking what your desired_caps and serverConfig is? Are you executing on a real device or sim? Also have you started appium as a separate process? mine looks like this:
I have configured the following configurarion in both android and ios(in ios adding a different desired caps).
Under my project directory, I have created following js files in a folder named Setup
appium_servers.js (you can also define your cloud credentials here if you are running the tests on cloud)
desired_caps.js (in the same file you can define the desired caps of ios)
exports.desiredCapsAndroid = {
appiumVersion: '1.6.3',
deviceName: 'yourdevicename',
platformVersion: '6.0.1',
platformName: 'Android',
name: 'Sample Test',
app: 'path of your ipa or apk',
unicodeKeyboard:true,
resetKeyboard:true
autoGrantPermissions:true
}
logging.js (used for logging the requests and response with different colours to make the log more readable)
"use strict";
exports.configure = function (driver) {
// See whats going on
driver.on('status', function (info) {
console.log(info.cyan);
});
driver.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
driver.on('http', function (meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});
};
setup.js (it contains all the required packages/libraries, just do npm install name to install any of them)
var wd = require("wd");
require('colors');
var mocha = require("mocha");
var should = require("should");
5.After that in my test file I have written:
"use strict";
require("../Setup/setup");
var testData = require("../Helper/test_data.js");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('../Setup/appium_servers.js');
require("mocha");
require("should");
describe("Test Case 1", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("../Setup/logging").configure(driver);
var desired = _.clone(require("../Setup/desired_caps.js").desiredCapsAndroid);
return driver
.init(desired)
.setImplicitWaitTimeout(5000);
});
after(function () {
return driver
.quit()
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
//For screenshot
if (this.currentTest.state !== 'passed'){
return driver.takeScreenshot().then(function(){
return driver.saveScreenshot('../Screenshots/')
})
}
});
I am using real device but configuration will remain same for emulators also except for the device name/uuid in desired caps.
I have installed appium globally by doing npm install -g appium and starting it as a separate process and then run test cases by going into the test directory and doing mocha test_file.js
Hope this helps.