"use strict";

var assert = require('chai').assert;
var xdTesting = require('../../lib/index')
var templates = require('../../lib/templates');

describe('MultiDevice - getCount', function () {
    var test = this;

    test.devices = {};
    test.baseUrl = "http://localhost:8090/";

    afterEach(function () {
        // Close browsers before completing a test
        return test.devices.endAll();
    });

    it('should count a single device @medium', function () {
        var options = {A: templates.devices.chrome()};
        return test.devices = xdTesting.multiremote(options)
            .getCount().then((count) => {
                assert.equal(count, 1);
                assert.equal(Object.keys(arguments).length, 0)
            });
    });

    it('should count two devices @medium', function () {
        var options = {A: templates.devices.chrome(), B: templates.devices.chrome()};
        return test.devices = xdTesting.multiremote(options)
            .getCount().then((count) => {
                assert.equal(count, 2);
                assert.equal(Object.keys(arguments).length, 0)
            });
    });

    it('should count several devices @medium', function () {
        var options = {
            A: templates.devices.chrome(),
            B: templates.devices.chrome(),
            C: templates.devices.chrome(),
            D: templates.devices.chrome()
        };
        return test.devices = xdTesting.multiremote(options)
            .getCount().then((count) => {
                assert.equal(count, 4);
                assert.equal(Object.keys(arguments).length, 0)
            });
    });

    it('should support method chaining @large', function () {
        var options = {A: templates.devices.chrome()};
        return test.devices = xdTesting.multiremote(options)
            .init()
            .url(test.baseUrl)
            .getCount().then((count) => {
                assert.equal(count, 1);
                assert.equal(Object.keys(arguments).length, 0)
            }).getCount().then((count) => {
                assert.equal(count, 1);
                assert.equal(Object.keys(arguments).length, 0)
            }).getUrl().then(url => {
                assert.equal(url, test.baseUrl);
            });
    });
});
@@ -356,16 +356,71 @@
  a test%0A
+        if (test.devices && test.devices.endAll) %7B%0A    
         
@@ -449,16 +449,26 @@
 dAll();%0A
+        %7D%0A
     %7D);%0A
@@ -2318,12 +2318,535 @@
 %0A    %7D);
+%0A%0A    it('should support selectById @large', function() %7B%0A        var options = %7B%0A            A: templates.devices.chrome(),%0A            B: templates.devices.chrome()%0A        %7D%0A        return test.devices = xdTesting.multiremote(options).init()%0A            .getCount().then(count =%3E %7B%0A                assert.equal(count, 2)%0A            %7D)%0A            .selectById('A', device =%3E device%0A                .getCount(count =%3E %7B%0A                    assert.equal(count, 1)%0A                %7D)%0A            )%0A            .end()%0A    %7D)
 %0A%7D);

Test getCount with selectById