Selenium テスト スイート内で BrowserMob-Proxy を使用しています。いくつかのテストのためにリファラーを変更したいと思います。2.0 ドキュメントの requestInterceptor を MyProxy クラスに追加しましたが、エラーは発生しませんが、Referer は変更されません。
今のところ、プロキシが作成される MyProxy クラスで requestInterceptor を機能させようとしています。最後に、各テストでリファラーを指定できるようにしたいと考えています。
requestInterceptor を機能させるための提案がある場合は、お知らせください。これが MyProxy クラスです。この問題のトラブルシューティングに役立つ他のコード例があれば教えてください。
import org.openqa.selenium.Proxy;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.ProxyServer;
import net.lightbody.bmp.proxy.http.BrowserMobHttpRequest;
import net.lightbody.bmp.proxy.http.RequestInterceptor;
public class MyProxy {
private ProxyServer proxy;
private boolean initialized;
public Har endCapture() throws Exception {
Thread.sleep(15000);
return this.proxy.getHar();
}
public Proxy getSeleniumProxy() {
return this.proxy.seleniumProxy();
}
public boolean isInitialized() throws Exception {
return this.initialized;
}
public void start() throws Exception {
int proxyPort = Integer.parseInt(System.getProperty("proxyPort"));
this.proxy = new ProxyServer(proxyPort);
this.proxy.start();
this.proxy.setCaptureHeaders(true);
this.proxy.setCaptureContent(true);
this.proxy.addRequestInterceptor(new RequestInterceptor() {
@Override
public void process(BrowserMobHttpRequest request, Har har) {
request.getMethod().removeHeaders("Referer");
request.getMethod().addHeader("Referer", "http://www.google.com");
}
});
this.initialized = true;
}
public void startCapture() throws Exception{
this.proxy.newHar("MyHar");
}
public void stop() throws Exception {
this.proxy.stop();
this.initialized = false;
}
}