Java ਦੇ RemoteWebDriver ਕਮਾਂਡ ਪ੍ਰੌਕਸੀ ਰਾਹੀਂ ਭੇਜੋ
Java ਪ੍ਰੋਗਰਾਮ ਨੂੰ ਫ਼ਾਰਵਰਡ ਪ੍ਰੌਕਸੀ ਰਾਹੀਂ ਦੂਰਵਰਤੀ WebDriver ਸੇਵਾ ਤੱਕ ਪਹੁੰਚਣਾ ਹੋਵੇ ਤਾਂ command executor ਉੱਤੇ ClientConfig ਸੈੱਟ ਕਰੋ।
Java runner → configured proxy → WebDriver service
remote browser → its own route → website
ਪਹਿਲੇ ਰਸਤੇ ਲਈ Java command executor ਸੰਰਚਿਤ ਕਰੋ:
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());
deployment ਪਾਥ ਸਮੇਤ ਅਸਲ Grid endpoint ਵਰਤੋ। ਲੋੜੀਂਦੇ Chrome ਵਿਕਲਪ ਰੱਖੋ ਅਤੇ driver.quit() ਨਾਲ ਸੈਸ਼ਨ ਮੁਕਾਓ।
ਇਹ Java ਪ੍ਰੋਗਰਾਮ ਦੇ HTTP ਕਨੈਕਸ਼ਨ ਲਈ java.net.Proxy ਹੈ। ਇਸ ਦੇ ਉਲਟ Selenium ਦੀ org.openqa.selenium.Proxy capability ਬ੍ਰਾਊਜ਼ਰ ਦੇ ਪੰਨਿਆਂ ਦਾ ਟ੍ਰੈਫਿਕ ਕੰਟਰੋਲ ਕਰਦੀ ਹੈ; ਦੂਜੇ ਰਸਤੇ ਨੂੰ ਵੀ ਪ੍ਰੌਕਸੀ ਚਾਹੀਦੀ ਹੋਵੇ ਤਾਂ ਹੀ ਇਸ ਨੂੰ ਨਾਲ ਵਰਤੋ।
ਸੈਸ਼ਨ ਬਣਾਉਣ ਜਾਂ ਕਮਾਂਡ ਭੇਜਣ ਦੀ ਅਸਫਲਤਾ ਪਹਿਲੇ ਰਸਤੇ ਨਾਲ ਸਬੰਧਤ ਹੈ। ਬਾਅਦ ਦਾ ਨੇਵੀਗੇਸ਼ਨ ਦੂਜੇ ਉੱਤੇ ਅਸਫਲ ਹੋ ਸਕਦਾ ਹੈ। Java ਪ੍ਰੋਗਰਾਮ ਦੇ ਵਿਚੋਲੇ ਉੱਤੇ ਪ੍ਰਮਾਣੀਕਰਨ ਲਈ ਉਸ HTTP ਟ੍ਰਾਂਸਪੋਰਟ ਦੀ ਸਮਰਥਿਤ ਵਿਧੀ ਚਾਹੀਦੀ ਹੈ; ਬ੍ਰਾਊਜ਼ਰ ਦਾ ਪ੍ਰਮਾਣੀਕਰਨ callback ਉਸ ਨੂੰ ਸੰਰਚਿਤ ਨਹੀਂ ਕਰਦਾ।