Appium Selenium Proxy
Connect Selenium / Appium java tests to the remote grid through a corporate proxy.
-
Appium Client 9
-
Appium Client 8 / Selenium 4
-
Appium Client 7 or below
-
Python client
Appium Client 9
The code was tested with Appium java client version 9.2.2
Appium client 9.x should be used to run tests on Appium server 2.x
Appium client 9.x supports Java 11 and above.
Copy the following code to your client-side:
Appium Client 9 via proxy
package proxy;
import io.appium.java_client.AppiumClientConfig;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.URL;
import java.util.Base64;
public class AppiumViaProxyClient9 {
private static String CLOUD_URL = "https://myorg.experitest.com/wd/hub";
private static String CLOUD_ACCESS_KEY = "<access_key>";
private static final String PROXY_HOST = "localhost";
private static int PROXY_PORT = 8888;
private static final String PROXY_USERNAME = "username";
private static final String PROXY_PASSWORD = "password";
public static void main(String[] args) throws Exception {
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
XCUITestOptions options = new XCUITestOptions()
.amend("deviceQuery", "@os='ios'")
.amend("accessKey", CLOUD_ACCESS_KEY)
.amend("appiumVersion", "2.2.2");
AppiumClientConfig appiumClientConfig = AppiumClientConfig.defaultConfig()
.baseUrl(new URL(CLOUD_URL))
.proxy(new Proxy(Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
.withFilter(httpHandler -> httpRequest -> {
httpRequest.setHeader("Proxy-Authorization", "Basic " +
Base64.getEncoder().encodeToString((PROXY_USERNAME + ":" + PROXY_PASSWORD).getBytes()));
return httpHandler.execute(httpRequest);
});
IOSDriver driver = new IOSDriver(appiumClientConfig, options);
System.out.println("Page source: " + driver.getPageSource());
driver.quit();
}
}