Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/lib/session.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 { Capabilities } = require('./capabilities')
21
22
/**
23
* Contains information about a single WebDriver session.
24
*/
25
class Session {
26
/**
27
* @param {string} id The session ID.
28
* @param {!./capabilities.Capabilities} capabilities
29
* The session capabilities.
30
*/
31
constructor(id, capabilities) {
32
/** @private {string} */
33
this.id_ = id
34
35
/** @private {!Capabilities} */
36
this.caps_ =
37
capabilities instanceof Capabilities
38
? /** @type {!Capabilities} */ (capabilities)
39
: new Capabilities(capabilities)
40
}
41
42
/**
43
* @return {string} This session's ID.
44
*/
45
getId() {
46
return this.id_
47
}
48
49
/**
50
* @return {!Capabilities} This session's capabilities.
51
*/
52
getCapabilities() {
53
return this.caps_
54
}
55
56
/**
57
* Retrieves the value of a specific capability.
58
* @param {string} key The capability to retrieve.
59
* @return {*} The capability value.
60
*/
61
getCapability(key) {
62
return this.caps_.get(key)
63
}
64
65
/**
66
* Returns the JSON representation of this object, which is just the string
67
* session ID.
68
* @return {string} The JSON representation of this Session.
69
*/
70
toJSON() {
71
return this.getId()
72
}
73
}
74
75
// PUBLIC API
76
77
module.exports = { Session }
78
79