"use strict"

var xdTesting = require('../lib/index');
var q = require('q');

var utility = {

    waitforTimeout: 30 * 1000,

    /**
     * @param devices
     * @returns {WebdriverIO.Client}
     */
    initWithDevices: function (devices) {

        var self = this;

        // Store id into device
        Object.keys(devices).forEach(function (id) {
            var device = devices[id];
            device['id'] = id;
            device['waitforTimeout'] = utility.waitforTimeout;
        });

        self.deviceOptions = devices;

        // New browser instance with WebdriverIO
        self.devices = xdTesting.multiremote(self.deviceOptions);

        var tileWidth = Math.floor(1600 / self.devicesCount());

        return self.devices.init()
            .timeoutsAsyncScript(15 * 1000)
            .then(function () {
                // Align windows on screen
                var x = 0;
                Object.keys(self.deviceOptions).forEach(deviceName => {
                    var device = self.devices.select(deviceName);
                    var width = self.deviceOptions[deviceName].width || tileWidth;
                    var height = self.deviceOptions[deviceName].height || 600;

                    // Set window sizes
                    device.windowHandleSize({width: width, height: height})

                    // Align window on screen
                    device.windowHandlePosition({x: x, y: 0});
                    x += tileWidth;
                });
            });
    },

    /**
     * @callback multiActionCallback
     * @param {WebdriverIO.Client} device
     */

    /**
     * Executes callback on devices matching deviceNames.
     * Returns a promise.
     * @param devices
     * @param deviceIds
     * @param {multiActionCallback} callback
     * @returns Q.Promise<T[]>
     */
    multiAction: function multiAction(devices, deviceIds, callback) {
        var promises = [];
        deviceIds.forEach(function (id) {
            var device = devices.select(id);
            promises.push(callback(device));
        });
        return q.all(promises);
    }

};

module.exports = utility;

@@ -134,38 +134,38 @@
 *%0A     * @param 
-device
+option
 s%0A     * @return
@@ -226,22 +226,22 @@
 nction (
-device
+option
 s) %7B%0A%0A  
@@ -316,22 +316,22 @@
 ct.keys(
-device
+option
 s).forEa
@@ -374,22 +374,22 @@
 evice = 
-device
+option
 s%5Bid%5D;%0A 
@@ -523,23 +523,88 @@
 tions = 
-devices
+options;%0A%0A        var tileWidth = Math.floor(1600 / self.devicesCount())
 ;%0A%0A     
@@ -629,16 +629,17 @@
 instance
+s
  with We
@@ -652,29 +652,28 @@
 rIO%0A        
-self.
+let 
 devices = xd
@@ -696,122 +696,16 @@
 ote(
-self.deviceOptions);%0A%0A        var tileWidth = Math.floor(1600 / self.devicesCount());%0A%0A        return self.devices
+options)
 .ini
@@ -882,28 +882,17 @@
 ct.keys(
-self.deviceO
+o
 ptions).
@@ -948,21 +948,16 @@
 evice = 
-self.
 devices.
@@ -974,17 +974,16 @@
 iceName)
-;
 %0A       
@@ -1007,28 +1007,17 @@
 width = 
-self.deviceO
+o
 ptions%5Bd
@@ -1037,33 +1037,32 @@
 dth %7C%7C tileWidth
-;
 %0A               
@@ -1079,28 +1079,17 @@
 eight = 
-self.deviceO
+o
 ptions%5Bd
@@ -1112,17 +1112,16 @@
 t %7C%7C 600
-;
 %0A%0A      
@@ -1338,17 +1338,16 @@
 , y: 0%7D)
-;
 %0A       
@@ -1373,17 +1373,16 @@
 ileWidth
-;
 %0A       
@@ -1405,24 +1405,48 @@
          %7D);
+%0A%0A        return devices
 %0A    %7D,%0A%0A   

Refactor utility.js