# proxy.js

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