Java의 RemoteWebDriver 명령을 프록시 경유로 보내기
Java 실행 프로그램이 포워드 프록시를 통해 원격 WebDriver 서비스에 접근해야 한다면 명령 실행기에 ClientConfig를 설정하세요.
Java runner → configured proxy → WebDriver service
remote browser → its own route → website
첫 번째 경로에는 Java 명령 실행기를 설정하세요.
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
var proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxy.example", 8080));
var config = ClientConfig.defaultConfig()
.baseUri(URI.create("https://grid.example/"))
.proxy(proxy);
var executor = new HttpCommandExecutor(config);
var driver = new RemoteWebDriver(executor, new ChromeOptions());
배포 경로를 포함한 실제 Grid 엔드포인트를 사용하세요. 필요한 Chrome 옵션을 유지하고 driver.quit()로 세션을 종료하세요.
여기서 쓰는 것은 Java 실행 프로그램의 HTTP 연결용 java.net.Proxy입니다. Selenium의 org.openqa.selenium.Proxy capability는 대신 브라우저의 페이지 트래픽을 제어합니다. 두 번째 경로에도 프록시가 필요한 경우에만 이것도 설정하세요.
세션 생성이나 명령 전송 실패는 첫 번째 경로에 속합니다. 이후 탐색은 두 번째 경로에서 실패할 수 있습니다. Java 실행 프로그램의 중간 프록시 인증에는 해당 HTTP 전송 계층이 지원하는 방식이 필요합니다. 브라우저 인증 콜백은 이를 설정하지 않습니다.