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