forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils-specs.js
181 lines (173 loc) · 7.65 KB
/
utils-specs.js
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { parseCapsForInnerDriver, insertAppiumPrefixes } from '../lib/utils';
import { BASE_CAPS, W3C_CAPS } from './helpers';
import _ from 'lodash';
const should = chai.should();
chai.use(chaiAsPromised);
describe('utils', function () {
describe('parseCapsForInnerDriver()', function () {
it('should return JSONWP caps unchanged if only JSONWP caps provided', function () {
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver(BASE_CAPS);
desiredCaps.should.deep.equal(BASE_CAPS);
processedJsonwpCapabilities.should.deep.equal(BASE_CAPS);
should.not.exist(processedW3CCapabilities);
protocol.should.equal('MJSONWP');
});
it('should return W3C caps unchanged if only W3C caps were provided', function () {
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver(undefined, W3C_CAPS);
desiredCaps.should.deep.equal(BASE_CAPS);
should.not.exist(processedJsonwpCapabilities);
processedW3CCapabilities.should.deep.equal(W3C_CAPS);
protocol.should.equal('W3C');
});
it('should return JSONWP and W3C caps if both were provided', function () {
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver(BASE_CAPS, W3C_CAPS);
desiredCaps.should.deep.equal(BASE_CAPS);
processedJsonwpCapabilities.should.deep.equal(BASE_CAPS);
processedW3CCapabilities.should.deep.equal(W3C_CAPS);
protocol.should.equal('W3C');
});
it('should include default capabilities in results', function () {
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(BASE_CAPS, W3C_CAPS, {}, {foo: 'bar'});
desiredCaps.should.deep.equal({foo: 'bar', ...BASE_CAPS});
processedJsonwpCapabilities.should.deep.equal({foo: 'bar', ...BASE_CAPS});
processedW3CCapabilities.alwaysMatch.should.deep.equal({'appium:foo': 'bar', ...insertAppiumPrefixes(BASE_CAPS)});
});
it('should rewrite default capabilities in results', function () {
const baseCapsWithDefault = Object.assign({}, BASE_CAPS, {
foo: 'baz',
'appium:foo2': 'baz2',
});
const w3cCapsWithDefault = _.cloneDeep(W3C_CAPS);
w3cCapsWithDefault.alwaysMatch.foo = 'baz';
w3cCapsWithDefault.alwaysMatch.foo2 = 'baz2';
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(baseCapsWithDefault, w3cCapsWithDefault, {}, {
foo: 'bar',
'appium:foo2': 'bar2',
});
desiredCaps.should.deep.equal({foo: 'baz', foo2: 'baz2', ...BASE_CAPS});
processedJsonwpCapabilities.should.deep.equal({foo: 'baz', foo2: 'baz2', ...BASE_CAPS});
processedW3CCapabilities.alwaysMatch.should.deep.equal({'appium:foo': 'baz', 'appium:foo2': 'baz2', ...insertAppiumPrefixes(BASE_CAPS)});
});
it('should reject if W3C caps are not passing constraints', function () {
const err = parseCapsForInnerDriver(undefined, W3C_CAPS, {hello: {presence: true}}).error;
err.message.should.match(/'hello' can't be blank/);
_.isError(err).should.be.true;
});
it('should only accept W3C caps that have passing constraints', function () {
let w3cCaps = {
...W3C_CAPS,
firstMatch: [
{foo: 'bar'},
{hello: 'world'},
],
};
let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver(BASE_CAPS, w3cCaps, {hello: {presence: true}});
const expectedResult = {hello: 'world', ...BASE_CAPS};
desiredCaps.should.deep.equal(expectedResult);
processedJsonwpCapabilities.should.deep.equal({...BASE_CAPS});
processedW3CCapabilities.alwaysMatch.should.deep.equal(insertAppiumPrefixes(expectedResult));
protocol.should.equal('W3C');
});
it('should add appium prefixes to W3C caps that are not standard in W3C', function () {
parseCapsForInnerDriver(undefined, {
alwaysMatch: {
platformName: 'Fake',
propertyName: 'PROP_NAME',
},
}).processedW3CCapabilities.should.deep.equal({
alwaysMatch: {
platformName: 'Fake',
'appium:propertyName': 'PROP_NAME',
},
firstMatch: [{}],
});
});
it('should merge extraneous MJSONWP caps into W3C', function () {
let jsonwpCaps = {
...BASE_CAPS,
automationName: 'Fake',
};
const {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver(jsonwpCaps, {
alwaysMatch: {platformName: 'Fake', propertyName: 'PROP_NAME'},
});
// We expect a combo of jsonwp caps and w3c provided caps with `appium:` prefix for non-standard caps
const expectedCaps = {};
for (let [key, value] of _.toPairs(jsonwpCaps)) {
if (key !== 'platformName') {
expectedCaps[`appium:${key}`] = value;
} else {
expectedCaps[key] = value;
}
}
expectedCaps['appium:propertyName'] = 'PROP_NAME';
processedW3CCapabilities.alwaysMatch.should.eql(expectedCaps);
desiredCaps.should.eql({
...jsonwpCaps,
propertyName: 'PROP_NAME',
});
processedJsonwpCapabilities.should.eql(jsonwpCaps);
protocol.should.equal('W3C');
});
it('should fix W3C caps by using MJSONWP if invalid W3C caps were provided', function () {
let w3cCapabilities = {
alwaysMatch: {platformName: 'Fake', propertyName: 'PROP_NAME'},
};
let constraints = {
deviceName: {
presence: true,
}
};
const {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities, protocol} = parseCapsForInnerDriver({...BASE_CAPS}, w3cCapabilities, constraints);
processedW3CCapabilities.should.exist;
desiredCaps.should.eql({...BASE_CAPS, propertyName: 'PROP_NAME'});
processedJsonwpCapabilities.should.eql(BASE_CAPS);
protocol.should.equal('W3C');
});
});
describe('insertAppiumPrefixes()', function () {
it('should apply prefixes to non-standard capabilities', function () {
insertAppiumPrefixes({
someCap: 'someCap',
}).should.deep.equal({
'appium:someCap': 'someCap',
});
});
it('should not apply prefixes to standard capabilities', function () {
insertAppiumPrefixes({
browserName: 'BrowserName',
platformName: 'PlatformName',
}).should.deep.equal({
browserName: 'BrowserName',
platformName: 'PlatformName',
});
});
it('should not apply prefixes to capabilities that already have a prefix', function () {
insertAppiumPrefixes({
'appium:someCap': 'someCap',
'moz:someOtherCap': 'someOtherCap',
}).should.deep.equal({
'appium:someCap': 'someCap',
'moz:someOtherCap': 'someOtherCap',
});
});
it('should apply prefixes to non-prefixed, non-standard capabilities; should not apply prefixes to any other capabilities', function () {
insertAppiumPrefixes({
'appium:someCap': 'someCap',
'moz:someOtherCap': 'someOtherCap',
browserName: 'BrowserName',
platformName: 'PlatformName',
someOtherCap: 'someOtherCap',
yetAnotherCap: 'yetAnotherCap',
}).should.deep.equal({
'appium:someCap': 'someCap',
'moz:someOtherCap': 'someOtherCap',
browserName: 'BrowserName',
platformName: 'PlatformName',
'appium:someOtherCap': 'someOtherCap',
'appium:yetAnotherCap': 'yetAnotherCap',
});
});
});
});