| 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 | goog.provide('webdriver.Session'); |
| 19 | |
| 20 | goog.require('webdriver.Capabilities'); |
| 21 | |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * Contains information about a WebDriver session. |
| 26 | * @param {string} id The session ID. |
| 27 | * @param {!(Object|webdriver.Capabilities)} capabilities The session |
| 28 | * capabilities. |
| 29 | * @constructor |
| 30 | */ |
| 31 | webdriver.Session = function(id, capabilities) { |
| 32 | |
| 33 | /** @private {string} */ |
| 34 | this.id_ = id; |
| 35 | |
| 36 | /** @private {!webdriver.Capabilities} */ |
| 37 | this.caps_ = new webdriver.Capabilities().merge(capabilities); |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * @return {string} This session's ID. |
| 43 | */ |
| 44 | webdriver.Session.prototype.getId = function() { |
| 45 | return this.id_; |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * @return {!webdriver.Capabilities} This session's capabilities. |
| 51 | */ |
| 52 | webdriver.Session.prototype.getCapabilities = function() { |
| 53 | return this.caps_; |
| 54 | }; |
| 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 | webdriver.Session.prototype.getCapability = function(key) { |
| 63 | return this.caps_.get(key); |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * Returns the JSON representation of this object, which is just the string |
| 69 | * session ID. |
| 70 | * @return {string} The JSON representation of this Session. |
| 71 | */ |
| 72 | webdriver.Session.prototype.toJSON = function() { |
| 73 | return this.getId(); |
| 74 | }; |