I'm trying to break up some procedural JavaScript code used for running an automation test. The code is a series of steps that execute selenium webdriver commands within the neustar load testing framework. The framework is not too important for the purposes of this review, except to know this code is not run in a browser. Its more the structure of the javascript I'm after feedback on, in terms of encapsulating the steps.The controller initializes the test, retrieves parameters for the virtual user and orchestrates running the steps. The steps object is a container for the individual steps in the test.Note the 'test' object is a global object provided by the framework, which I have mocked for the purpose of the review. See it in action here.I want the steps object to contain some reusable functions. I've added one called utilityFunction and called it from a step.The code is a wrapper around a selenium automation test that is run in the cloud using neustar. I'm looking for a way to break up multiple steps in the test into a clean, maintainable structure to allow me to better re-use and encapsulate distinct steps in the test automation. The 'test' object can be ignored, it's simply there to mock the neustar global object.This is a simple framework to run step 1, then step 2 through to step n, e.g. navigate to site, logon, create new order, submit order etc...Please evaluate the quality of the JavaScript, as well as the pattern for running a series of steps while being able to control what happens before and after each step. function testController(steps) {    this.steps = steps;    // simplified params this will be read from a service    this.params = { Param1: Value1, Param2: Value2 };    this.runAll = function () {        test.beginTransaction();        for (var s in this.steps) {            test.beginStep(this.steps[s].description, this.steps[s].timeout);            this.steps[s].execute(this.params);            test.endStep();        }        test.endTransaction();    }}function testSteps() {    var utilityFunction = function (v) {        console.log(** calling util with value:  + v +  ***);    }    this.step1 = {        description: first step,        timeout: 1000,        execute: function (params) {            console.log(executing  + this.description);        }    }    this.step2 = {        description: second step,        timeout: 30000,        execute: function (params) {            console.log(executing  + this.description);            utilityFunction(hello);        }    }}// mock test objectvar test = {    beginTransaction: function () {        console.log(beginning transaction);    },    endTransaction: function () {        console.log(ending transaction);    },    beginStep: function (name, timeout) {        console.log(begin step  + name);    },    endStep: function () {        console.log(end step);    }}var steps = new testSteps();//steps.utilityFunction(world);var tc = new testController(steps);tc.runAll();
Modelling an automation test controller and test steps
javascript