aboutsummaryrefslogtreecommitdiff
path: root/node_modules/selenium-webdriver/test/lib/capabilities_test.js
blob: 0d0c67c9a31c56285602bd6d3b897e26e00de52c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

'use strict';

const Capabilities = require('../../lib/capabilities').Capabilities;
const Symbols = require('../../lib/symbols');

const assert = require('assert');

describe('Capabilities', function() {
  it('can set and unset a capability', function() {
    let caps = new Capabilities();
    assert.equal(undefined, caps.get('foo'));
    assert.ok(!caps.has('foo'));

    caps.set('foo', 'bar');
    assert.equal('bar', caps.get('foo'));
    assert.ok(caps.has('foo'));

    caps.set('foo', null);
    assert.equal(null, caps.get('foo'));
    assert.ok(caps.has('foo'));
  });

  it('requires string capability keys', function() {
    let caps = new Capabilities();
    assert.throws(() => caps.set({}, 'hi'));
  });

  it('can merge capabilities', function() {
    let caps1 = new Capabilities()
        .set('foo', 'bar')
        .set('color', 'red');

    let caps2 = new Capabilities()
        .set('color', 'green');

    assert.equal('bar', caps1.get('foo'));
    assert.equal('red', caps1.get('color'));
    assert.equal('green', caps2.get('color'));
    assert.equal(undefined, caps2.get('foo'));

    caps2.merge(caps1);
    assert.equal('bar', caps1.get('foo'));
    assert.equal('red', caps1.get('color'));
    assert.equal('red', caps2.get('color'));
    assert.equal('bar', caps2.get('foo'));
  });

  it('can be initialized from a hash object', function() {
    let caps = new Capabilities({'one': 123, 'abc': 'def'});
    assert.equal(123, caps.get('one'));
    assert.equal('def', caps.get('abc'));
  });

  it('can be initialized from a map', function() {
    let m = new Map([['one', 123], ['abc', 'def']]);

    let caps = new Capabilities(m);
    assert.equal(123, caps.get('one'));
    assert.equal('def', caps.get('abc'));
  });

  describe('serialize', function() {
    it('works for simple capabilities', function() {
      let m = new Map([['one', 123], ['abc', 'def']]);
      let caps = new Capabilities(m);
      assert.deepEqual({one: 123, abc: 'def'}, caps[Symbols.serialize]());
    });

    it('does not omit capabilities set to a false-like value', function() {
      let caps = new Capabilities;
      caps.set('bool', false);
      caps.set('number', 0);
      caps.set('string', '');

      assert.deepEqual(
          {bool: false, number: 0, string: ''},
          caps[Symbols.serialize]());
    });

    it('omits capabilities with a null value', function() {
      let caps = new Capabilities;
      caps.set('foo', null);
      caps.set('bar', 123);
      assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
    });

    it('omits capabilities with an undefined value', function() {
      let caps = new Capabilities;
      caps.set('foo', undefined);
      caps.set('bar', 123);
      assert.deepEqual({bar: 123}, caps[Symbols.serialize]());
    });
  });
});