proxy.js

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