Java ၏ RemoteWebDriver command များကို proxy မှတစ်ဆင့် ပို့ခြင်း
Java ပရိုဂရမ်က remote WebDriver ဝန်ဆောင်မှုသို့ forward proxy မှတစ်ဆင့် သွားရမည်ဆိုလျှင် 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());
ဝန်ဆောင်မှုတင်ထားသော path အပါအဝင် တကယ့် Grid endpoint ကို သုံးပါ။ လိုအပ်သော Chrome option များကို ထိန်းထားပြီး driver.quit() ဖြင့် session ကို အဆုံးသတ်ပါ။
ဤသည်မှာ Java ပရိုဂရမ်၏ HTTP ချိတ်ဆက်မှုအတွက် java.net.Proxy ဖြစ်သည်။ Selenium ၏ org.openqa.selenium.Proxy capability ကတော့ ဘရောက်ဇာစာမျက်နှာများ၏ traffic ကို ထိန်းချုပ်သည်။ ဒုတိယလမ်းကြောင်းတွင်ပါ proxy လိုအပ်မှ ၎င်းကို ထပ်သုံးပါ။
session ဖန်တီးခြင်း သို့မဟုတ် command ပို့ခြင်း မအောင်မြင်ခြင်းသည် ပထမလမ်းကြောင်းနှင့် သက်ဆိုင်သည်။ နောက်ပိုင်း စာမျက်နှာဖွင့်ရာတွင် ဒုတိယလမ်းကြောင်း၌ မအောင်မြင်နိုင်သည်။ Java ပရိုဂရမ်၏ ကြားခံတွင် အထောက်အထားစစ်ဆေးရန် ထို HTTP transport ပံ့ပိုးသော နည်းလမ်းလိုသည်။ ဘရောက်ဇာ၏ authentication callback က ၎င်းကို မသတ်မှတ်ပေးပါ။