---
title: Configuring Appium tests with Proxy | TestingBot
description: Route all HTTP and HTTPS traffic from an iOS or Android device through
  a proxy during your Appium tests on TestingBot. Useful for traffic inspection, HAR
  capture and mocking.
source_url:
  html: https://testingbot.com/support/app-automate/appium/proxy
  md: https://testingbot.com/support/app-automate/appium/proxy.md
---

# 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](https://testingbot.com/support/app-automate/appium/options#geo) or latency testing.

[Ruby](https://testingbot.com#) [Python](https://testingbot.com#) [PHP](https://testingbot.com#) [Java](https://testingbot.com#) [NodeJS](https://testingbot.com#) [C#](https://testingbot.com#)

```ruby
desired_caps = {
  'platformName' => 'Android',
  'appium:automationName' => 'UiAutomator2',
  '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,
  appium_lib: { server_url: 'https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub' }
}, true)
```

```java
UiAutomator2Options options = new UiAutomator2Options();

// Set basic capabilities
options.setPlatformName("Android");
options.setAutomationName("UiAutomator2");
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);
```

```php
$capabilities = array(
    'platformName' => 'Android',
    'appium:automationName' => 'UiAutomator2',
    '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
    )
);
// The proxy is declared in the W3C 'proxy' capability above, which configures the proxy on the device.
// Do NOT pass a proxy as the 5th/6th args of RemoteWebDriver::create(); those set the client-to-server HTTP proxy and would break the connection to the hub.
$web_driver = RemoteWebDriver::create('https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub', $capabilities);
```

```python
capabilities = {
    "platformName": "Android",
    "appium:automationName": "UiAutomator2",
    "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
    }
}

from appium import webdriver
from appium.options.android import UiAutomator2Options

options = UiAutomator2Options().load_capabilities(capabilities)
driver = webdriver.Remote("https://hub.testingbot.com/wd/hub", options=options)
```

```javascript
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:automationName': 'UiAutomator2',
    '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);
```

```csharp
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Android";
options.AddAdditionalAppiumOption("appium:automationName", "UiAutomator2");
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);
```

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
