Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/remote_test.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict'
19
20
const assert = require('node:assert')
21
const path = require('node:path')
22
const io = require('selenium-webdriver/io')
23
const cmd = require('selenium-webdriver/lib/command')
24
const remote = require('selenium-webdriver/remote')
25
const { CancellationError } = require('selenium-webdriver/http/util')
26
27
describe('DriverService', function () {
28
describe('start()', function () {
29
var service
30
31
beforeEach(function () {
32
service = new remote.DriverService(process.execPath, {
33
port: 1234,
34
args: ['-e', 'process.exit(1)'],
35
})
36
})
37
38
afterEach(function () {
39
return service.kill()
40
})
41
42
it('fails if child-process dies', function () {
43
return service.start(500).then(expectFailure, verifyFailure)
44
})
45
46
function verifyFailure(e) {
47
assert.ok(!(e instanceof CancellationError))
48
assert.strictEqual('Server terminated early with status 1', e.message)
49
}
50
51
function expectFailure() {
52
throw Error('expected to fail')
53
}
54
})
55
})
56
57
describe('FileDetector', function () {
58
class ExplodingDriver {
59
execute() {
60
throw Error('unexpected call')
61
}
62
}
63
64
it('returns the original path if the file does not exist', function () {
65
return io.tmpDir().then((dir) => {
66
let theFile = path.join(dir, 'not-there')
67
return new remote.FileDetector()
68
.handleFile(new ExplodingDriver(), theFile)
69
.then((f) => assert.strictEqual(f, theFile))
70
})
71
})
72
73
it('returns the original path if it is a directory', function () {
74
return io.tmpDir().then((dir) => {
75
return new remote.FileDetector().handleFile(new ExplodingDriver(), dir).then((f) => assert.strictEqual(f, dir))
76
})
77
})
78
79
it('attempts to upload valid files', function () {
80
return io.tmpFile().then((theFile) => {
81
return new remote.FileDetector()
82
.handleFile(
83
new (class FakeDriver {
84
execute(command) {
85
assert.strictEqual(command.getName(), cmd.Name.UPLOAD_FILE)
86
assert.strictEqual(typeof command.getParameters()['file'], 'string')
87
return Promise.resolve('success!')
88
}
89
})(),
90
theFile,
91
)
92
.then((f) => assert.strictEqual(f, 'success!'))
93
})
94
})
95
})
96
97