@appium/base-driver 8.3.0 → 8.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/build/lib/basedriver/capabilities.js +2 -4
  2. package/build/lib/basedriver/commands/event.js +2 -4
  3. package/build/lib/basedriver/commands/find.js +2 -4
  4. package/build/lib/basedriver/commands/index.js +2 -4
  5. package/build/lib/basedriver/commands/log.js +2 -4
  6. package/build/lib/basedriver/commands/session.js +2 -4
  7. package/build/lib/basedriver/commands/settings.js +2 -4
  8. package/build/lib/basedriver/commands/timeout.js +2 -4
  9. package/build/lib/basedriver/desired-caps.js +2 -4
  10. package/build/lib/basedriver/device-settings.js +2 -4
  11. package/build/lib/basedriver/driver.js +17 -6
  12. package/build/lib/basedriver/helpers.js +2 -4
  13. package/build/lib/basedriver/logger.js +2 -4
  14. package/build/lib/constants.js +2 -4
  15. package/build/lib/express/crash.js +2 -4
  16. package/build/lib/express/express-logging.js +2 -4
  17. package/build/lib/express/idempotency.js +2 -4
  18. package/build/lib/express/logger.js +2 -4
  19. package/build/lib/express/middleware.js +2 -4
  20. package/build/lib/express/server.js +2 -4
  21. package/build/lib/express/static.js +2 -4
  22. package/build/lib/express/websocket.js +2 -4
  23. package/build/lib/helpers/capabilities.js +2 -4
  24. package/build/lib/index.js +2 -4
  25. package/build/lib/jsonwp-proxy/protocol-converter.js +2 -4
  26. package/build/lib/jsonwp-proxy/proxy.js +2 -4
  27. package/build/lib/jsonwp-status/status.js +2 -4
  28. package/build/lib/protocol/errors.js +2 -4
  29. package/build/lib/protocol/helpers.js +2 -4
  30. package/build/lib/protocol/index.js +2 -4
  31. package/build/lib/protocol/protocol.js +2 -4
  32. package/build/lib/protocol/routes.js +2 -4
  33. package/build/lib/protocol/validators.js +2 -4
  34. package/build/test/basedriver/README.md +5 -0
  35. package/build/test/basedriver/driver-e2e-tests.js +2 -4
  36. package/build/test/basedriver/driver-tests.js +2 -4
  37. package/build/test/basedriver/index.js +2 -4
  38. package/build/test/e2e/basedriver/driver.e2e.spec.js +15 -0
  39. package/build/test/e2e/basedriver/helpers.e2e.spec.js +192 -0
  40. package/build/test/e2e/basedriver/websockets.e2e.spec.js +82 -0
  41. package/build/test/e2e/express/server.e2e.spec.js +159 -0
  42. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +59 -0
  43. package/build/test/e2e/protocol/fake-driver.js +163 -0
  44. package/build/test/e2e/protocol/helpers.js +25 -0
  45. package/build/test/e2e/protocol/protocol.e2e.spec.js +1186 -0
  46. package/build/test/helpers.js +2 -4
  47. package/build/test/unit/basedriver/capabilities.spec.js +672 -0
  48. package/build/test/unit/basedriver/capability.spec.js +353 -0
  49. package/build/test/unit/basedriver/commands/event.spec.js +110 -0
  50. package/build/test/unit/basedriver/commands/log.spec.js +85 -0
  51. package/build/test/unit/basedriver/driver.spec.js +15 -0
  52. package/build/test/unit/basedriver/helpers.spec.js +151 -0
  53. package/build/test/unit/basedriver/timeout.spec.js +135 -0
  54. package/build/test/unit/express/server.spec.js +155 -0
  55. package/build/test/unit/express/static.spec.js +26 -0
  56. package/build/test/unit/jsonwp-proxy/mock-request.js +91 -0
  57. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +171 -0
  58. package/build/test/unit/jsonwp-proxy/proxy.spec.js +292 -0
  59. package/build/test/unit/jsonwp-proxy/url.spec.js +165 -0
  60. package/build/test/unit/jsonwp-status/status.spec.js +34 -0
  61. package/build/test/unit/protocol/errors.spec.js +390 -0
  62. package/build/test/unit/protocol/routes.spec.js +80 -0
  63. package/build/test/unit/protocol/validator.spec.js +149 -0
  64. package/lib/basedriver/driver.js +15 -4
  65. package/package.json +14 -9
  66. package/test/basedriver/README.md +5 -0
  67. package/test/basedriver/driver-e2e-tests.js +1 -1
  68. package/build/test/basedriver/capabilities-specs.js +0 -674
  69. package/build/test/basedriver/capability-specs.js +0 -355
  70. package/build/test/basedriver/commands/event-specs.js +0 -112
  71. package/build/test/basedriver/commands/log-specs.js +0 -87
  72. package/build/test/basedriver/driver-e2e-specs.js +0 -17
  73. package/build/test/basedriver/driver-specs.js +0 -17
  74. package/build/test/basedriver/helpers-e2e-specs.js +0 -194
  75. package/build/test/basedriver/helpers-specs.js +0 -153
  76. package/build/test/basedriver/timeout-specs.js +0 -137
  77. package/build/test/basedriver/websockets-e2e-specs.js +0 -84
  78. package/build/test/express/server-e2e-specs.js +0 -161
  79. package/build/test/express/server-specs.js +0 -157
  80. package/build/test/express/static-specs.js +0 -28
  81. package/build/test/jsonwp-proxy/mock-request.js +0 -93
  82. package/build/test/jsonwp-proxy/protocol-converter-specs.js +0 -173
  83. package/build/test/jsonwp-proxy/proxy-e2e-specs.js +0 -61
  84. package/build/test/jsonwp-proxy/proxy-specs.js +0 -294
  85. package/build/test/jsonwp-proxy/url-specs.js +0 -167
  86. package/build/test/jsonwp-status/status-specs.js +0 -36
  87. package/build/test/protocol/errors-specs.js +0 -388
  88. package/build/test/protocol/fake-driver.js +0 -165
  89. package/build/test/protocol/helpers.js +0 -27
  90. package/build/test/protocol/protocol-e2e-specs.js +0 -1188
  91. package/build/test/protocol/routes-specs.js +0 -82
  92. package/build/test/protocol/validator-specs.js +0 -151
  93. package/test/basedriver/capabilities-specs.js +0 -537
  94. package/test/basedriver/capability-specs.js +0 -383
  95. package/test/basedriver/commands/event-specs.js +0 -74
  96. package/test/basedriver/commands/log-specs.js +0 -79
  97. package/test/basedriver/driver-e2e-specs.js +0 -8
  98. package/test/basedriver/driver-specs.js +0 -8
  99. package/test/basedriver/fixtures/BadZippedApp.zip +0 -1
  100. package/test/basedriver/fixtures/FakeAndroidApp.apk +0 -1
  101. package/test/basedriver/fixtures/FakeAndroidApp.asd +0 -0
  102. package/test/basedriver/fixtures/FakeIOSApp.app +0 -1
  103. package/test/basedriver/fixtures/FakeIOSApp.app.zip +0 -0
  104. package/test/basedriver/fixtures/FakeIOSApp.ipa +0 -0
  105. package/test/basedriver/fixtures/custom-element-finder-bad.js +0 -5
  106. package/test/basedriver/fixtures/custom-element-finder.js +0 -29
  107. package/test/basedriver/helpers-e2e-specs.js +0 -187
  108. package/test/basedriver/helpers-specs.js +0 -137
  109. package/test/basedriver/timeout-specs.js +0 -128
  110. package/test/basedriver/websockets-e2e-specs.js +0 -75
@@ -1,187 +0,0 @@
1
- import path from 'path';
2
- import url from 'url';
3
- import { fs } from '@appium/support';
4
- import { configureApp } from '../../lib/basedriver/helpers';
5
- import http from 'http';
6
- import finalhandler from 'finalhandler';
7
- import serveStatic from 'serve-static';
8
- import contentDisposition from 'content-disposition';
9
- import B from 'bluebird';
10
- import {TEST_HOST, getTestPort} from '../helpers';
11
-
12
-
13
- function getFixture (file) {
14
- // XXX: __dirname disallowed in native ESM
15
- return path.resolve(__dirname, '..', '..', '..', 'test', 'basedriver', 'fixtures', file);
16
- }
17
-
18
- describe('app download and configuration', function () {
19
- describe('configureApp', function () {
20
- it('should get the path for a local .app', async function () {
21
- let newAppPath = await configureApp(getFixture('FakeIOSApp.app'), '.app');
22
- newAppPath.should.contain('FakeIOSApp.app');
23
- let contents = await fs.readFile(newAppPath, 'utf8');
24
- contents.should.eql('this is not really an app\n');
25
- });
26
- it('should get the path for a local .apk', async function () {
27
- let newAppPath = await configureApp(getFixture('FakeAndroidApp.apk'), '.apk');
28
- newAppPath.should.contain('FakeAndroidApp.apk');
29
- let contents = await fs.readFile(newAppPath, 'utf8');
30
- contents.should.eql('this is not really an apk\n');
31
- });
32
- it('should unzip and get the path for a local .app.zip', async function () {
33
- let newAppPath = await configureApp(getFixture('FakeIOSApp.app.zip'), '.app');
34
- newAppPath.should.contain('FakeIOSApp.app');
35
- let contents = await fs.readFile(newAppPath, 'utf8');
36
- contents.should.eql('this is not really an app\n');
37
- });
38
- it('should unzip and get the path for a local .ipa', async function () {
39
- let newAppPath = await configureApp(getFixture('FakeIOSApp.ipa'), '.app');
40
- newAppPath.should.contain('FakeIOSApp.app');
41
- let contents = await fs.readFile(newAppPath, 'utf8');
42
- contents.should.eql('this is not really an app\n');
43
- });
44
- it('should fail for a bad zip file', async function () {
45
- await configureApp(getFixture('BadZippedApp.zip'), '.app')
46
- .should.be.rejectedWith(/PK/);
47
- });
48
- it('should fail if extensions do not match', async function () {
49
- await configureApp(getFixture('FakeIOSApp.app'), '.wrong')
50
- .should.be.rejectedWith(/did not have extension/);
51
- });
52
- it('should fail if zip file does not contain an app whose extension matches', async function () {
53
- await configureApp(getFixture('FakeIOSApp.app.zip'), '.wrong')
54
- .should.be.rejectedWith(/did not have extension/);
55
- });
56
- describe('should download an app from the web', function () {
57
- let port;
58
- let serverUrl;
59
-
60
- before(async function () {
61
- port = await getTestPort(true);
62
- serverUrl = `http://${TEST_HOST}:${port}`;
63
- });
64
-
65
- describe('server not available', function () {
66
- it('should handle server not available', async function () {
67
- await configureApp(`${serverUrl}/FakeIOSApp.app.zip`, '.app')
68
- .should.eventually.be.rejectedWith(/ECONNREFUSED/);
69
- });
70
- });
71
- describe('server available', function () {
72
- // use a local server so there is no dependency on the internet
73
- let server;
74
- before(function () {
75
- const dir = path.resolve(__dirname, '..', '..', '..', 'test', 'basedriver', 'fixtures');
76
- const serve = serveStatic(dir, {
77
- index: false,
78
- setHeaders: (res, path) => {
79
- res.setHeader('Content-Disposition', contentDisposition(path));
80
- },
81
- });
82
-
83
- server = http.createServer(function (req, res) {
84
- if (req.url.indexOf('missing') !== -1) {
85
- res.writeHead(404);
86
- res.end();
87
- return;
88
- }
89
- // for testing zip file content types
90
- const contentType = new URLSearchParams(url.parse(req.url).search).get('content-type');
91
- if (contentType !== null) {
92
- res.setHeader('content-type', contentType);
93
- }
94
- serve(req, res, finalhandler(req, res));
95
- });
96
- const close = server.close.bind(server);
97
- server.close = async function () {
98
- // pause a moment or we get ECONRESET errors
99
- await B.delay(1000);
100
- return await new B((resolve, reject) => {
101
- server.on('close', resolve);
102
- close((err) => {
103
- if (err) reject(err); // eslint-disable-line curly
104
- });
105
- });
106
- };
107
- server.listen(port);
108
- });
109
- after(async function () {
110
- await server.close();
111
- });
112
-
113
- it('should download zip file', async function () {
114
- let newAppPath = await configureApp(`${serverUrl}/FakeIOSApp.app.zip`, '.app');
115
- newAppPath.should.contain('FakeIOSApp.app');
116
- let contents = await fs.readFile(newAppPath, 'utf8');
117
- contents.should.eql('this is not really an app\n');
118
- });
119
- it('should download zip file with query string', async function () {
120
- let newAppPath = await configureApp(`${serverUrl}/FakeIOSApp.app.zip?sv=abc&sr=def`, '.app');
121
- newAppPath.should.contain('.app');
122
- let contents = await fs.readFile(newAppPath, 'utf8');
123
- contents.should.eql('this is not really an app\n');
124
- });
125
- it('should download an app file', async function () {
126
- let newAppPath = await configureApp(`${serverUrl}/FakeIOSApp.app`, '.app');
127
- newAppPath.should.contain('.app');
128
- let contents = await fs.readFile(newAppPath, 'utf8');
129
- contents.should.eql('this is not really an app\n');
130
- });
131
- it('should accept multiple extensions', async function () {
132
- let newAppPath = await configureApp(`${serverUrl}/FakeIOSApp.app.zip`, ['.app', '.aab']);
133
- newAppPath.should.contain('FakeIOSApp.app');
134
- let contents = await fs.readFile(newAppPath, 'utf8');
135
- contents.should.eql('this is not really an app\n');
136
- });
137
- it('should download an apk file', async function () {
138
- let newAppPath = await configureApp(`${serverUrl}/FakeAndroidApp.apk`, '.apk');
139
- newAppPath.should.contain('.apk');
140
- let contents = await fs.readFile(newAppPath, 'utf8');
141
- contents.should.eql('this is not really an apk\n');
142
- });
143
- it('should handle zip file that cannot be downloaded', async function () {
144
- await configureApp(`${serverUrl}/missing/FakeIOSApp.app.zip`, '.app')
145
- .should.eventually.be.rejected;
146
- });
147
- it('should handle invalid protocol', async function () {
148
- await configureApp('file://C:/missing/FakeIOSApp.app.zip', '.app')
149
- .should.eventually.be.rejectedWith(/is not supported/);
150
- await configureApp(`ftp://${TEST_HOST}:${port}/missing/FakeIOSApp.app.zip`, '.app')
151
- .should.eventually.be.rejectedWith(/is not supported/);
152
- });
153
- it('should handle missing file in Windows path format', async function () {
154
- await configureApp('C:\\missing\\FakeIOSApp.app.zip', '.app')
155
- .should.eventually.be.rejectedWith(/does not exist or is not accessible/);
156
- });
157
- it('should recognize zip mime types and unzip the downloaded file', async function () {
158
- let newAppPath = await configureApp(`${serverUrl}/FakeAndroidApp.asd?content-type=${encodeURIComponent('application/zip')}`, '.apk');
159
- newAppPath.should.contain('FakeAndroidApp.apk');
160
- newAppPath.should.not.contain('.asd');
161
- let contents = await fs.readFile(newAppPath, 'utf8');
162
- contents.should.eql('this is not really an apk\n');
163
- });
164
- it('should recognize zip mime types with parameter and unzip the downloaded file', async function () {
165
- let newAppPath = await configureApp(`${serverUrl}/FakeAndroidApp.asd?content-type=${encodeURIComponent('application/zip; parameter=value')}`, '.apk');
166
- newAppPath.should.contain('FakeAndroidApp.apk');
167
- newAppPath.should.not.contain('.asd');
168
- let contents = await fs.readFile(newAppPath, 'utf8');
169
- contents.should.eql('this is not really an apk\n');
170
- });
171
- it('should recognize zip mime types and unzip the downloaded file with query string', async function () {
172
- let newAppPath = await configureApp(`${serverUrl}/FakeAndroidApp.asd?content-type=${encodeURIComponent('application/zip')}&sv=abc&sr=def`, '.apk');
173
- newAppPath.should.contain('FakeAndroidApp.apk');
174
- newAppPath.should.not.contain('.asd');
175
- let contents = await fs.readFile(newAppPath, 'utf8');
176
- contents.should.eql('this is not really an apk\n');
177
- });
178
- it('should treat an unknown mime type as an app', async function () {
179
- let newAppPath = await configureApp(`${serverUrl}/FakeAndroidApp.apk?content-type=${encodeURIComponent('application/bip')}`, '.apk');
180
- newAppPath.should.contain('.apk');
181
- let contents = await fs.readFile(newAppPath, 'utf8');
182
- contents.should.eql('this is not really an apk\n');
183
- });
184
- });
185
- });
186
- });
187
- });
@@ -1,137 +0,0 @@
1
- import { zip, fs, tempDir } from '@appium/support';
2
- import { configureApp, isPackageOrBundle, duplicateKeys, parseCapsArray } from '../../lib/basedriver/helpers';
3
- import sinon from 'sinon';
4
-
5
-
6
- describe('helpers', function () {
7
- describe('#isPackageOrBundle', function () {
8
- it('should accept packages and bundles', function () {
9
- isPackageOrBundle('io.appium.testapp').should.be.true;
10
- });
11
- it('should not accept non-packages or non-bundles', function () {
12
- isPackageOrBundle('foo').should.be.false;
13
- isPackageOrBundle('/path/to/an.app').should.be.false;
14
- isPackageOrBundle('/path/to/an.apk').should.be.false;
15
- });
16
- });
17
-
18
- describe('#duplicateKeys', function () {
19
- it('should translate key in an object', function () {
20
- duplicateKeys({'foo': 'hello world'}, 'foo', 'bar').should.eql({'foo': 'hello world', 'bar': 'hello world'});
21
- });
22
- it('should translate key in an object within an object', function () {
23
- duplicateKeys({'key': {'foo': 'hello world'}}, 'foo', 'bar').should.eql({'key': {'foo': 'hello world', 'bar': 'hello world'}});
24
- });
25
- it('should translate key in an object with an array', function () {
26
- duplicateKeys([
27
- {'key': {'foo': 'hello world'}},
28
- {'foo': 'HELLO WORLD'}
29
- ], 'foo', 'bar').should.eql([
30
- {'key': {'foo': 'hello world', 'bar': 'hello world'}},
31
- {'foo': 'HELLO WORLD', 'bar': 'HELLO WORLD'}
32
- ]);
33
- });
34
- it('should duplicate both keys', function () {
35
- duplicateKeys({
36
- 'keyOne': {
37
- 'foo': 'hello world',
38
- },
39
- 'keyTwo': {
40
- 'bar': 'HELLO WORLD',
41
- },
42
- }, 'foo', 'bar').should.eql({
43
- 'keyOne': {
44
- 'foo': 'hello world',
45
- 'bar': 'hello world',
46
- },
47
- 'keyTwo': {
48
- 'bar': 'HELLO WORLD',
49
- 'foo': 'HELLO WORLD',
50
- }
51
- });
52
- });
53
- it('should not do anything to primitives', function () {
54
- [0, 1, -1, true, false, null, undefined, '', 'Hello World'].forEach((item) => {
55
- should.equal(duplicateKeys(item), item);
56
- });
57
- });
58
- it('should rename keys on big complex objects', function () {
59
- const input = [
60
- {'foo': 'bar'},
61
- {
62
- hello: {
63
- world: {
64
- 'foo': 'BAR',
65
- }
66
- },
67
- foo: 'bahr'
68
- },
69
- 'foo',
70
- null,
71
- 0
72
- ];
73
- const expectedOutput = [
74
- {'foo': 'bar', 'FOO': 'bar'},
75
- {
76
- hello: {
77
- world: {
78
- 'foo': 'BAR',
79
- 'FOO': 'BAR',
80
- }
81
- },
82
- foo: 'bahr',
83
- FOO: 'bahr'
84
- },
85
- 'foo',
86
- null,
87
- 0
88
- ];
89
- duplicateKeys(input, 'foo', 'FOO').should.deep.equal(expectedOutput);
90
- });
91
- });
92
-
93
- describe('#configureApp', function () {
94
- let sandbox;
95
-
96
- beforeEach(function () {
97
- sandbox = sinon.createSandbox();
98
- sandbox.stub(zip, 'extractAllTo').resolves();
99
- sandbox.stub(zip, 'assertValidZip').resolves();
100
- sandbox.stub(fs, 'mv').resolves();
101
- sandbox.stub(fs, 'stat').resolves({
102
- isFile: () => true,
103
- isDirectory: () => false,
104
- });
105
- sandbox.stub(fs, 'exists').resolves(true);
106
- sandbox.stub(fs, 'hash').resolves('0xDEADBEEF');
107
- sandbox.stub(fs, 'glob').resolves(['/path/to/an.apk']);
108
- sandbox.stub(fs, 'rimraf').resolves();
109
- sandbox.stub(tempDir, 'openDir').resolves('/some/dir');
110
- });
111
-
112
- afterEach(function () {
113
- sandbox.restore();
114
- });
115
-
116
- it('should pass "useSystemUnzip" flag through to @appium/support', async function () {
117
- await configureApp('/path/to/an.apk.zip', '.apk');
118
- zip.extractAllTo.getCall(0).lastArg.useSystemUnzip.should.be.true;
119
- });
120
- });
121
- });
122
-
123
- describe('parseCapsArray', function () {
124
- it('should parse string into array', function () {
125
- parseCapsArray('/tmp/my/app.zip').should.eql(['/tmp/my/app.zip']);
126
- });
127
- it('should parse array as string into array', function () {
128
- parseCapsArray('["/tmp/my/app.zip"]').should.eql(['/tmp/my/app.zip']);
129
- parseCapsArray('["/tmp/my/app.zip","/tmp/my/app2.zip"]').should.eql([
130
- '/tmp/my/app.zip',
131
- '/tmp/my/app2.zip'
132
- ]);
133
- });
134
- it('should return an array without change', function () {
135
- parseCapsArray(['a', 'b']).should.eql(['a', 'b']);
136
- });
137
- });
@@ -1,128 +0,0 @@
1
- import BaseDriver from '../../lib';
2
- import { createSandbox } from 'sinon';
3
-
4
- describe('timeout', function () {
5
- let driver = new BaseDriver();
6
- let implicitWaitSpy;
7
- let sandbox;
8
- beforeEach(function () {
9
- sandbox = createSandbox();
10
- driver.implicitWaitMs = 0;
11
- implicitWaitSpy = sandbox.spy(driver, 'setImplicitWait');
12
- });
13
- afterEach(function () {
14
- sandbox.restore();
15
- });
16
- describe('timeouts', function () {
17
- describe('errors', function () {
18
- it('should throw an error if something random is sent', async function () {
19
- await driver.timeouts('random timeout', 'howdy').should.eventually.be.rejected;
20
- });
21
- it('should throw an error if timeout is negative', async function () {
22
- await driver.timeouts('random timeout', -42).should.eventually.be.rejected;
23
- });
24
- it('should throw an errors if timeout type is unknown', async function () {
25
- await driver.timeouts('random timeout', 42).should.eventually.be.rejected;
26
- });
27
- it('should throw an error if something random is sent to scriptDuration', async function () {
28
- await driver.timeouts(undefined, undefined, 123, undefined, undefined).should.eventually.be.rejected;
29
- });
30
- it('should throw an error if something random is sent to pageLoadDuration', async function () {
31
- await driver.timeouts(undefined, undefined, undefined, 123, undefined).should.eventually.be.rejected;
32
- });
33
- });
34
- describe('implicit wait', function () {
35
- it('should call setImplicitWait when given an integer', async function () {
36
- await driver.timeouts('implicit', 42);
37
- implicitWaitSpy.calledOnce.should.be.true;
38
- implicitWaitSpy.firstCall.args[0].should.equal(42);
39
- driver.implicitWaitMs.should.eql(42);
40
- });
41
- it('should call setImplicitWait when given a string', async function () {
42
- await driver.timeouts('implicit', '42');
43
- implicitWaitSpy.calledOnce.should.be.true;
44
- implicitWaitSpy.firstCall.args[0].should.equal(42);
45
- driver.implicitWaitMs.should.eql(42);
46
- });
47
- it('should call setImplicitWait when given an integer to implicitDuration', async function () {
48
- await driver.timeouts(undefined, undefined, undefined, undefined, 42);
49
- implicitWaitSpy.calledOnce.should.be.true;
50
- implicitWaitSpy.firstCall.args[0].should.equal(42);
51
- driver.implicitWaitMs.should.eql(42);
52
- });
53
- it('should call setImplicitWait when given a string to implicitDuration', async function () {
54
- await driver.timeouts(undefined, undefined, undefined, undefined, '42');
55
- implicitWaitSpy.calledOnce.should.be.true;
56
- implicitWaitSpy.firstCall.args[0].should.equal(42);
57
- driver.implicitWaitMs.should.eql(42);
58
- });
59
- });
60
- });
61
- describe('implicitWait', function () {
62
- it('should call setImplicitWait when given an integer', async function () {
63
- await driver.implicitWait(42);
64
- implicitWaitSpy.calledOnce.should.be.true;
65
- implicitWaitSpy.firstCall.args[0].should.equal(42);
66
- driver.implicitWaitMs.should.eql(42);
67
- });
68
- it('should call setImplicitWait when given a string', async function () {
69
- await driver.implicitWait('42');
70
- implicitWaitSpy.calledOnce.should.be.true;
71
- implicitWaitSpy.firstCall.args[0].should.equal(42);
72
- driver.implicitWaitMs.should.eql(42);
73
- });
74
- it('should throw an error if something random is sent', async function () {
75
- await driver.implicitWait('howdy').should.eventually.be.rejected;
76
- });
77
- it('should throw an error if timeout is negative', async function () {
78
- await driver.implicitWait(-42).should.eventually.be.rejected;
79
- });
80
- });
81
-
82
- describe('set implicit wait', function () {
83
- it('should set the implicit wait with an integer', function () {
84
- driver.setImplicitWait(42);
85
- driver.implicitWaitMs.should.eql(42);
86
- });
87
- describe('with managed driver', function () {
88
- let managedDriver1 = new BaseDriver();
89
- let managedDriver2 = new BaseDriver();
90
- before(function () {
91
- driver.addManagedDriver(managedDriver1);
92
- driver.addManagedDriver(managedDriver2);
93
- });
94
- after(function () {
95
- driver.managedDrivers = [];
96
- });
97
- it('should set the implicit wait on managed drivers', function () {
98
- driver.setImplicitWait(42);
99
- driver.implicitWaitMs.should.eql(42);
100
- managedDriver1.implicitWaitMs.should.eql(42);
101
- managedDriver2.implicitWaitMs.should.eql(42);
102
- });
103
- });
104
- });
105
- describe('set new command timeout', function () {
106
- it('should set the new command timeout with an integer', function () {
107
- driver.setNewCommandTimeout(42);
108
- driver.newCommandTimeoutMs.should.eql(42);
109
- });
110
- describe('with managed driver', function () {
111
- let managedDriver1 = new BaseDriver();
112
- let managedDriver2 = new BaseDriver();
113
- before(function () {
114
- driver.addManagedDriver(managedDriver1);
115
- driver.addManagedDriver(managedDriver2);
116
- });
117
- after(function () {
118
- driver.managedDrivers = [];
119
- });
120
- it('should set the new command timeout on managed drivers', function () {
121
- driver.setNewCommandTimeout(42);
122
- driver.newCommandTimeoutMs.should.eql(42);
123
- managedDriver1.newCommandTimeoutMs.should.eql(42);
124
- managedDriver2.newCommandTimeoutMs.should.eql(42);
125
- });
126
- });
127
- });
128
- });
@@ -1,75 +0,0 @@
1
- import _ from 'lodash';
2
- import { server, routeConfiguringFunction,
3
- DEFAULT_WS_PATHNAME_PREFIX } from '../../lib';
4
- import { FakeDriver } from '../protocol/fake-driver';
5
- import WebSocket from 'ws';
6
- import B from 'bluebird';
7
- import {TEST_HOST, getTestPort} from '../helpers';
8
-
9
-
10
- describe('Websockets (e2e)', function () {
11
- let baseServer;
12
- let driver;
13
- let port;
14
- const SESSION_ID = 'foo';
15
- const WS_DATA = 'Hello';
16
-
17
- before(async function () {
18
- driver = new FakeDriver();
19
- driver.sessionId = SESSION_ID;
20
- port = await getTestPort();
21
- baseServer = await server({
22
- routeConfiguringFunction: routeConfiguringFunction(driver),
23
- port,
24
- });
25
- });
26
- after(async function () {
27
- await baseServer.close();
28
- });
29
-
30
- describe('web sockets support', function () {
31
- it('should be able to add websocket handler and remove it', async function () {
32
- const wss = new WebSocket.Server({
33
- noServer: true,
34
- });
35
- wss.on('connection', (ws) => {
36
- if (ws && ws.readyState === WebSocket.OPEN) {
37
- ws.send(WS_DATA);
38
- }
39
- });
40
- const previousListenerCount = baseServer.listenerCount('upgrade');
41
- const endpoint = `${DEFAULT_WS_PATHNAME_PREFIX}/hello`;
42
- const timeout = 5000;
43
- await baseServer.addWebSocketHandler(endpoint, wss);
44
- baseServer.listenerCount('upgrade').should.be.above(previousListenerCount);
45
- _.keys(await baseServer.getWebSocketHandlers()).length.should.eql(1);
46
- await new B((resolve, reject) => {
47
- const client = new WebSocket(`ws://${TEST_HOST}:${port}${endpoint}`);
48
- client.on('connection', (ws, req) => {
49
- ws.should.not.be.empty;
50
- req.connection.remoteAddress.should.not.be.empty;
51
- });
52
- client.on('message', (data) => {
53
- data.should.eql(WS_DATA);
54
- resolve();
55
- });
56
- client.on('error', reject);
57
- setTimeout(() => reject(new Error('No websocket messages have been received after the timeout')),
58
- timeout);
59
- });
60
-
61
- (await baseServer.removeWebSocketHandler(endpoint)).should.be.true;
62
- _.keys(await baseServer.getWebSocketHandlers()).length.should.eql(0);
63
- await new B((resolve, reject) => {
64
- const client = new WebSocket(`ws://${TEST_HOST}:${port}${endpoint}`);
65
- client.on('message', (data) =>
66
- reject(new Error(`No websocket messages are expected after the handler ` +
67
- `has been removed. '${data}' is received instead. `))
68
- );
69
- client.on('error', resolve);
70
- setTimeout(resolve, timeout);
71
- });
72
- baseServer.listenerCount('upgrade').should.be.above(previousListenerCount);
73
- });
74
- });
75
- });