Skip to main content

Configure a device with a proxy

You can use Appium or Selenium WebDriver to configure a proxy on the remote Android or iOS device, at the start of your test.

This makes sure that all traffic on the device will go through the external proxy, which can be useful to do geolocation testing or latency testing.

desired_caps = {
  'platformName' => 'Android',
  'appium:deviceName' => 'Pixel 9',
  'appium:platformVersion' => '16.0',
  'appium:app' => 'https://testingbot.com/appium/sample.apk',
  'tb:options' => {
    'realDevice' => true
  }
}

# Set up the proxy settings
proxy = {
  'proxyType' => 'manual',  # Proxy type (manual or system)
  'httpProxy' => 'http://your-proxy-server:8080',  # Replace with your HTTP proxy URL
  'sslProxy' => 'http://your-proxy-server:8080',  # Replace with your SSL proxy URL
  'noProxy' => 'localhost,127.0.0.1'  # Optional: bypass proxy for specific hosts
}

# Add proxy to desired capabilities
desired_caps['proxy'] = proxy

# Initialize the Appium driver
driver = Appium::Driver.new({caps: desired_caps}, true)
UiAutomator2Options options = new UiAutomator2Options();

// Set basic capabilities
options.setPlatformName("Android");
options.setCapability("appium:deviceName", "Pixel 9");
options.setCapability("appium:platformVersion", "16.0");
options.setCapability("appium:app", "https://testingbot.com/appium/sample.apk");

// Set TestingBot-specific options
Map<String, Object> tbOptions = new HashMap<>();
tbOptions.put("realDevice", true);
options.setCapability("tb:options", tbOptions);

// Set up proxy settings
Proxy proxy = new Proxy();
proxy.setHttpProxy("http://your-proxy-server:8080"); // Replace with your HTTP proxy URL
proxy.setSslProxy("http://your-proxy-server:8080"); // Replace with your SSL proxy URL

// Apply the proxy settings to the capabilities
options.setProxy(proxy);

// Initialize the driver with TestingBot Appium server URL
URL appiumServerUrl = new URL("https://hub.testingbot.com/wd/hub");
AndroidDriver driver = new AndroidDriver(appiumServerUrl, options);
$capabilities = array(
    'platformName' => 'Android',
    'appium:app' => 'https://testingbot.com/appium/sample.apk',
    'appium:deviceName' => 'Pixel 9',
    'appium:platformVersion' => '16.0',
    'tb:options' => array(
        'realDevice' => true
    ),
    'proxy' => array(
        'proxyType' => 'manual',  // Proxy type, "manual" for custom proxy settings
        'httpProxy' => 'http://your-proxy-server:8080',  // Replace with your HTTP proxy
        'sslProxy' => 'http://your-proxy-server:8080',  // Replace with your SSL proxy (HTTPS traffic)
        'noProxy' => 'localhost,127.0.0.1'  // Optional: addresses that should bypass the proxy
    )
);
$web_driver = RemoteWebDriver::create('https://hub.testingbot.com/wd/hub', $capabilities, null, null, PROXY_URL, PROXY_PORT);
capabilities = {
    "platformName": "Android",
    "appium:deviceName": "Pixel 9",
    "appium:platformVersion": "16.0",
    "appium:app": "https://testingbot.com/appium/sample.apk",
    "tb:options": {
        "realDevice": True
    },
    "proxy": {
        "proxyType": "manual",  # Or "system" if you want to use system proxy
        "httpProxy": "http://your-proxy-server:8080",  # Replace with your proxy server
        "sslProxy": "http://your-proxy-server:8080",  # Replace with your proxy server for SSL
        "noProxy": "localhost,127.0.0.1"  # Optional: specify addresses to bypass the proxy
    }
}

driver = webdriver.Remote(
    command_executor="https://hub.testingbot.com/wd/hub",
    options=capabilities
)
const { remote } = require('webdriverio');

const capabilities = {
  hostname: 'hub.testingbot.com',
  port: 443,
  protocol: 'https',
  path: '/wd/hub',
  user: 'api_key',
  key: 'api_secret',
  capabilities: {
    'platformName': 'Android',
    'appium:deviceName': 'Pixel 9',
    'appium:platformVersion': '16.0',
    'appium:app': 'https://testingbot.com/appium/sample.apk',
    'tb:options': {
      'name': 'My First App Test',
      'realDevice': true
    },
    'proxy': {
      proxyType: 'manual',
      httpProxy: 'http://proxy-server:8080', // Replace with your proxy server URL
      sslProxy: 'http://proxy-server:8080', // If needed for SSL connections
      noProxy: '' // You can define URLs to bypass the proxy
    }
  }
};

const driver = await remote(capabilities);
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Android";
options.AddAdditionalAppiumOption("appium:deviceName", "Pixel 9");
options.AddAdditionalAppiumOption("appium:platformVersion", "16.0");
options.AddAdditionalAppiumOption("appium:app", "https://testingbot.com/appium/sample.apk");

// Set TestingBot-specific options
var tbOptions = new Dictionary<string, object>
{
    ["realDevice"] = true
};
options.AddAdditionalAppiumOption("tb:options", tbOptions);

// Set up proxy using the Proxy class
Proxy proxy = new Proxy();
proxy.HttpProxy = "http://your-proxy-server:8080";  // Replace with your proxy URL
proxy.SslProxy = "http://your-proxy-server:8080";  // Replace with your proxy URL
proxy.NoProxy = "localhost,127.0.0.1";  // Optional: bypass proxy for specific addresses

// Apply the proxy to the Appium options
options.Proxy = proxy;

// Initialize the driver
AndroidDriver driver = new AndroidDriver(new Uri("https://hub.testingbot.com/wd/hub"), options);
Was this page helpful?

Looking for More Help?

Have questions or need more information?
You can reach us via the following channels: