Running chained automations

I am at the point where I can run automations through a real device (iOS, using javascript for a language). I have been playing around with creating separate automations as their own functions, and chaining them together but have not been able to get anything to work. For example, I want to have a login function, which I can call on it’s own or have it chained to another function to test that a specific function will return with a success, but I would of course need to be logged in to do so. Does anyone have any experience with this?

You can try to use wd client. See API here https://github.com/admc/wd/blob/master/doc/api.md

and script will be like this:

"use strict";

var wd = require("wd");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

var desired = {
	"appium-version": "1.0",
	platformName: "Android",
	platformVersion: "4.3",
	deviceName: "android",
	appPackage: "your app package",
	appActivity: "your app activity"
};

var browser = wd.promiseChainRemote("0.0.0.0", 4723);

browser.init(desired).then(function() {
	return browser
            .elementByName("element name").click()
		.[more wd api here]
		.fin(function() {
		     return browser.quit();
		});
}).done();