# lib/webdriver/session.js

1 | // Copyright 2011 Software Freedom Conservancy. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | goog.provide('webdriver.Session');
16 |
17 | goog.require('webdriver.Capabilities');
18 |
19 |
20 |
21 | /**
22 | * Contains information about a WebDriver session.
23 | * @param {string} id The session ID.
24 | * @param {!(Object|webdriver.Capabilities)} capabilities The session
25 | * capabilities.
26 | * @constructor
27 | */
28 | webdriver.Session = function(id, capabilities) {
29 |
30 | /** @private {string} */
31 | this.id_ = id;
32 |
33 | /** @private {!webdriver.Capabilities} */
34 | this.caps_ = new webdriver.Capabilities().merge(capabilities);
35 | };
36 |
37 |
38 | /**
39 | * @return {string} This session's ID.
40 | */
41 | webdriver.Session.prototype.getId = function() {
42 | return this.id_;
43 | };
44 |
45 |
46 | /**
47 | * @return {!webdriver.Capabilities} This session's capabilities.
48 | */
49 | webdriver.Session.prototype.getCapabilities = function() {
50 | return this.caps_;
51 | };
52 |
53 |
54 | /**
55 | * Retrieves the value of a specific capability.
56 | * @param {string} key The capability to retrieve.
57 | * @return {*} The capability value.
58 | */
59 | webdriver.Session.prototype.getCapability = function(key) {
60 | return this.caps_.get(key);
61 | };
62 |
63 |
64 | /**
65 | * Returns the JSON representation of this object, which is just the string
66 | * session ID.
67 | * @return {string} The JSON representation of this Session.
68 | */
69 | webdriver.Session.prototype.toJSON = function() {
70 | return this.getId();
71 | };