7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SeleniumWebdriver+JUnit+browsermob-proxyでブラウザのログを取得

Last updated at Posted at 2014-06-14

#目的
・ブラウザ内のflashなどのコンテンツの呼び出しURL解析のため

#コード

package site;

import java.io.FileOutputStream;
import java.io.IOException;

import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.ProxyServer;
import net.lightbody.bmp.proxy.jetty.http.HttpContext;
import net.lightbody.bmp.proxy.jetty.http.HttpException;
import net.lightbody.bmp.proxy.jetty.http.HttpRequest;

import org.apache.commons.httpclient.Header;
import org.apache.http.HttpRequestInterceptor;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class Google {

    private static WebDriver driver;

    @Test
    public void searchForSeleniumWebsite() throws Exception {

    	ProxyServer server = new ProxyServer(9978);
        server.start();
        server.setCaptureHeaders(true);
        server.setCaptureContent(true);
        server.newHar("test");

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "localhost");
        profile.setPreference("network.proxy.http_port", 9978);

        WebDriver driver = new FirefoxDriver(profile);

        driver.get("http://www.youtube.com/watch?v=xxxxxxxx");

        Har har1 = server.getHar();

        FileOutputStream fos = new FileOutputStream("log.log");
        har1.writeTo(fos);

        driver.quit();
        server.stop();

    }


}

#今後の追加予定
@DataPointでパラメータテスト
 外部ファイル読み出しでデータ分割

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?