Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 1201e66

Browse files
committed
Added http proxy and port vars to support tests running on a remote server that's behind a proxy
1 parent a5aa0d7 commit 1201e66

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Remote/HttpCommandExecutor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,20 @@ class HttpCommandExecutor implements WebDriverCommandExecutor {
117117

118118
/**
119119
* @param string $url
120+
* @param string|null $http_proxy
121+
* @param int|null $http_proxy_port
120122
*/
121-
public function __construct($url) {
123+
public function __construct($url, $http_proxy = null, $http_proxy_port = null) {
122124
$this->url = $url;
123125
$this->curl = curl_init();
124126

127+
if (!empty($http_proxy)) {
128+
curl_setopt($this->curl, CURLOPT_PROXY, $http_proxy);
129+
if (!empty($http_proxy_port)) {
130+
curl_setopt($this->curl, CURLOPT_PROXYPORT, $http_proxy_port);
131+
}
132+
}
133+
125134
// Get credentials from $url (if any)
126135
$matches = null;
127136
if (preg_match("/^(https?:\/\/)(.*):(.*)@(.*?)/U", $url, $matches)) {

lib/Remote/RemoteWebDriver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ protected function __construct() {}
6060
* @param DesiredCapabilities|array $desired_capabilities The desired capabilities
6161
* @param int|null $connection_timeout_in_ms
6262
* @param int|null $request_timeout_in_ms
63+
* @param string|null $http_proxy The proxy to tunnel requests through
64+
* @param int|null $http_proxy_port
6365
* @return RemoteWebDriver
6466
*/
6567
public static function create(
6668
$url = 'http://localhost:4444/wd/hub',
6769
$desired_capabilities = null,
6870
$connection_timeout_in_ms = null,
69-
$request_timeout_in_ms = null
71+
$request_timeout_in_ms = null,
72+
$http_proxy = null,
73+
$http_proxy_port = null
7074
) {
7175
$url = preg_replace('#/+$#', '', $url);
7276

@@ -76,7 +80,7 @@ public static function create(
7680
$desired_capabilities = $desired_capabilities->toArray();
7781
}
7882

79-
$executor = new HttpCommandExecutor($url);
83+
$executor = new HttpCommandExecutor($url, $http_proxy, $http_proxy_port);
8084
if ($connection_timeout_in_ms !== null) {
8185
$executor->setConnectionTimeout($connection_timeout_in_ms);
8286
}

0 commit comments

Comments
 (0)