This article will explain how to configure a proxy server in the Applitools Eyes SDK to address issues such as connection refused or connection timeout when using Applitools Eyes behind a proxy server.
Please find below the instructions for setting a proxy server in the relevant languages:
Java:
eyes.setProxy(new ProxySettings("http://YOUR-PROXY-URI"));
or
eyes.setProxy(new ProxySettings("http://YOUR-PROXY-URI", YOUR_USER, YOUR_PASSWORD));
Please make sure to add the commands before calling eyes.open(...) and also import the below package:
import com.applitools.eyes.ProxySettings;
Ruby:
eyes.set_proxy("https://proxy", "user", "password").
Note that the user and password parameters are optional.
Python:
Configure the environment variable HTTPS_PROXY:
import os
os.environ['HTTPS_PROXY'] = "http://localhost:8888"
.Net (C#):
var proxyURI = new Uri(string.Format("{0}:{1}", proxyURL, port));
WebProxy proxy = new WebProxy(proxyURI, true, null);
eyes.Proxy = proxy;
Or:
var proxyURI = new Uri(string.Format("{0}:{1}", proxyURL, port));
ICredentials credentials = new NetworkCredential(username, password);
WebProxy proxy = new WebProxy(proxyURI, true, null, credentials);
eyes.Proxy = proxy;
JavaScript (@applitools/eyes-selenium)
var proxyInfo = {
url: pHost,
username: pUser,
password: pPass,
isHttpOnly: isHttpOnly
};
eyes.setProxy(proxyInfo);
JavaScript (eyes.selenium)
eyes.setProxy("http://YOUR-PROXY-URI");
or
eyes.setProxy("http://YOUR-PROXY-URI", YOUR_USER, YOUR_PASSWORD);
or
1. npm install tunnel-agent
2. add 'applitools-http-proxy.js' to your project :
var tunnel = require('tunnel-agent');
var https = require('https');
var __request = https.request;
var proxy = { host: '', port: 0 };
https.request = function (options, callback) {
if (options.host.indexOf('applitools') > -1) {
var tunnelingAgent = tunnel.httpsOverHttp({
proxy: {
host: proxy.host,
port: proxy.port
}
});
options.agent = tunnelingAgent;
}
return __request(options, callback);
};
module.exports = function (host, port) {
proxy.host = host;
proxy.port = port;
};
3. in your app in the beginning insert the line:
require('./applitools-http- proxy.js')("proxy_ip", port);
Full example:
Full example:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
require('./applitools-http-proxy.js')("84.42.3.33", 3128);
var Eyes = require('eyes.selenium').Eyes;
var eyes = new Eyes();
eyes.setApiKey(APPLITOOLS_APIKEY);
try {
eyes.open(driver, 'Applitools', 'Test Web Page', {width: 800, height: 600}).then(function (driver) {
driver.get('http://www.applitools.com ');
/* Visual validation point #1 */
eyes.checkWindow('Test Web Page');
driver.findElement(webdriver.By.css('.read_more')).click();
/* Visual validation point #2 */
eyes.checkWindow('Features Page');
eyes.close();
});
} finally {
eyes.abortIfNotClosed();
}
driver.quit();