# lib/webdriver/abstractbuilder.js

    1// Copyright 2012 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 at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.1415goog.provide('webdriver.AbstractBuilder');1617goog.require('webdriver.Capabilities');18goog.require('webdriver.process');19202122/**23 * Creates new {@code webdriver.WebDriver} clients.  Upon instantiation, each24 * Builder will configure itself based on the following environment variables:25 * <dl>26 *   <dt>{@code webdriver.AbstractBuilder.SERVER_URL_ENV}</dt>27 *   <dd>Defines the remote WebDriver server that should be used for command28 *       command execution; may be overridden using29 *       {@code webdriver.AbstractBuilder.prototype.usingServer}.</dd>30 * </dl>31 * @constructor32 */33webdriver.AbstractBuilder = function() {3435  /**36   * URL of the remote server to use for new clients; initialized from the37   * value of the {@link webdriver.AbstractBuilder.SERVER_URL_ENV} environment38   * variable, but may be overridden using39   * {@link webdriver.AbstractBuilder#usingServer}.40   * @private {string}41   */42  this.serverUrl_ = webdriver.process.getEnv(43      webdriver.AbstractBuilder.SERVER_URL_ENV);4445  /**46   * The desired capabilities to use when creating a new session.47   * @private {!webdriver.Capabilities}48   */49  this.capabilities_ = new webdriver.Capabilities();50};515253/**54 * Environment variable that defines the URL of the WebDriver server that55 * should be used for all new WebDriver clients. This setting may be overridden56 * using {@code #usingServer(url)}.57 * @type {string}58 * @const59 * @see webdriver.process.getEnv60 */61webdriver.AbstractBuilder.SERVER_URL_ENV = 'wdurl';626364/**65 * The default URL of the WebDriver server to use if66 * {@link webdriver.AbstractBuilder.SERVER_URL_ENV} is not set.67 * @type {string}68 * @const69 */70webdriver.AbstractBuilder.DEFAULT_SERVER_URL = 'http://localhost:4444/wd/hub';717273/**74 * Configures which WebDriver server should be used for new sessions. Overrides75 * the value loaded from the {@link webdriver.AbstractBuilder.SERVER_URL_ENV}76 * upon creation of this instance.77 * @param {string} url URL of the server to use.78 * @return {!webdriver.AbstractBuilder} This Builder instance for chain calling.79 */80webdriver.AbstractBuilder.prototype.usingServer = function(url) {81  this.serverUrl_ = url;82  return this;83};848586/**87 * @return {string} The URL of the WebDriver server this instance is configured88 *     to use.89 */90webdriver.AbstractBuilder.prototype.getServerUrl = function() {91  return this.serverUrl_;92};939495/**96 * Sets the desired capabilities when requesting a new session. This will97 * overwrite any previously set desired capabilities.98 * @param {!(Object|webdriver.Capabilities)} capabilities The desired99 *     capabilities for a new session.100 * @return {!webdriver.AbstractBuilder} This Builder instance for chain calling.101 */102webdriver.AbstractBuilder.prototype.withCapabilities = function(capabilities) {103  this.capabilities_ = new webdriver.Capabilities(capabilities);104  return this;105};106107108/**109 * @return {!webdriver.Capabilities} The current desired capabilities for this110 *     builder.111 */112webdriver.AbstractBuilder.prototype.getCapabilities = function() {113  return this.capabilities_;114};115116117/**118 * Builds a new {@link webdriver.WebDriver} instance using this builder's119 * current configuration.120 * @return {!webdriver.WebDriver} A new WebDriver client.121 */122webdriver.AbstractBuilder.prototype.build = goog.abstractMethod;