| 1 | // Copyright 2013 Selenium committers |
| 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 | /** |
| 16 | * @fileoverview Defines functions for configuring a webdriver proxy: |
| 17 | * |
| 18 | * var webdriver = require('selenium-webdriver'), |
| 19 | * proxy = require('selenium-webdriver/proxy'); |
| 20 | * |
| 21 | * var driver = new webdriver.Builder() |
| 22 | * .withCapabilities(webdriver.Capabilities.chrome()) |
| 23 | * .setProxy(proxy.manual({http: 'host:1234'})) |
| 24 | * .build(); |
| 25 | */ |
| 26 | |
| 27 | 'use strict'; |
| 28 | |
| 29 | var util = require('util'); |
| 30 | |
| 31 | |
| 32 | |
| 33 | // PUBLIC API |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * Configures WebDriver to bypass all browser proxies. |
| 38 | * @return {!webdriver.ProxyConfig} A new proxy configuration object. |
| 39 | */ |
| 40 | exports.direct = function() { |
| 41 | return {proxyType: 'direct'}; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * Manually configures the browser proxy. The following options are |
| 47 | * supported: |
| 48 | * |
| 49 | * - `ftp`: Proxy host to use for FTP requests |
| 50 | * - `http`: Proxy host to use for HTTP requests |
| 51 | * - `https`: Proxy host to use for HTTPS requests |
| 52 | * - `bypass`: A list of hosts requests should directly connect to, |
| 53 | * bypassing any other proxies for that request. May be specified as a |
| 54 | * comma separated string, or a list of strings. |
| 55 | * |
| 56 | * Behavior is undefined for FTP, HTTP, and HTTPS requests if the |
| 57 | * corresponding key is omitted from the configuration options. |
| 58 | * |
| 59 | * @param {{ftp: (string|undefined), |
| 60 | * http: (string|undefined), |
| 61 | * https: (string|undefined), |
| 62 | * bypass: (string|!Array.<string>|undefined)}} options Proxy |
| 63 | * configuration options. |
| 64 | * @return {!webdriver.ProxyConfig} A new proxy configuration object. |
| 65 | */ |
| 66 | exports.manual = function(options) { |
| 67 | return { |
| 68 | proxyType: 'manual', |
| 69 | ftpProxy: options.ftp, |
| 70 | httpProxy: options.http, |
| 71 | sslProxy: options.https, |
| 72 | noProxy: util.isArray(options.bypass) ? |
| 73 | options.bypass.join(',') : options.bypass |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * Configures WebDriver to configure the browser proxy using the PAC file at |
| 80 | * the given URL. |
| 81 | * @param {string} url URL for the PAC proxy to use. |
| 82 | * @return {!webdriver.ProxyConfig} A new proxy configuration object. |
| 83 | */ |
| 84 | exports.pac = function(url) { |
| 85 | return { |
| 86 | proxyType: 'pac', |
| 87 | proxyAutoconfigUrl: url |
| 88 | }; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | /** |
| 93 | * Configures WebDriver to use the current system's proxy. |
| 94 | * @return {!webdriver.ProxyConfig} A new proxy configuration object. |
| 95 | */ |
| 96 | exports.system = function() { |
| 97 | return {proxyType: 'system'}; |
| 98 | }; |