2016-09-06 3 views
0

BrowserMob을 셀렌 테스트에 통합하려고했습니다. http에서 작동하는 웹 사이트에서는 제대로 작동하지만 https 웹 사이트에서는 브라우저가 작동을 멈추고 HAR 파일에는 요청이 포함되지 않습니다.Selenium (Chrome) 및 BrowserMob이 https에 작동하지 않습니다

https 사이트로 이동할 때 브라우저에서이 오류가 발생합니다.

"프록시 서버에 문제가 있거나 주소가 잘못되었습니다."

여기 내 코드입니다.

public class Browsermob { 

    BrowserMobProxy proxy = new BrowserMobProxyServer(); 

    @Test 
    public void browsermobtest() { 


    proxy.start(9091); 

    // get the Selenium proxy object 
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); 


    // configure it as a desired capability 
    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); 
    System.setProperty("webdriver.chrome.driver", "C:/Users/Madis/Documents/chromedriver.exe"); 

    WebDriver driver = new ChromeDriver(capabilities); 

    // enable more detailed HAR capture, if desired (see CaptureType for the complete list) 
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT); 

    // create a new HAR with the label "google.com" 
    proxy.newHar("http://www.google.com/"); 

    // open google.com 
    driver.get("https://www.google.ee/#gfe_rd=cr"); 
    driver.findElement(By.cssSelector("#gb_70")).click(); 



    } 

    @AfterMethod 
    public void Afterthetest() { 

    // get the HAR data 
    Har har = proxy.getHar(); 

    File harFile = new File("C:/Users/Madis/Documents/har.har"); 
    try { 
     har.writeTo(harFile); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    } 
} 

답변

0

나는 그것을 작동시킬 수 있었다.그것이 작동 할 수 있도록하기 위해

Caught an exception on ClientToProxyConnection 
java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.fromHost(Ljava/lang/String;)Lcom/google/common/net/HostAndPort; 

하여 문제가 발생 된 browsermob 로그를 log4j에 추가 및 디버깅 후 내 받는다는 프로젝트에 종속성을 추가했다. 이 문제가 해결되어 https 사이트와 http 사이트의 트래픽을 캡처 할 수있었습니다.

<dependency> 
<groupId>com.google.guava</groupId> 
<artifactId>guava</artifactId> 
<version>20.0</version> 
</dependency> 
+0

구아바는 이미 BMP에 종속되어 있습니다. 어떤 BMP 의존성을 끌어 들이고 있습니까? 내가 \t net.lightbody.bmp에게 \t browsermob 코어 \t 2.1.4 \t을 사용하고 –

+0

@JasonHoetger. 현재 github에 표시된 하나. –

+0

browsermob-core는 이미 구아바 20에 달려 있습니다. 아마도 당신은 구아바를 당신의 어딘가에 포함시킬 것입니까? 'mvn dependency : tree'를 사용하여 확신 할 수 있습니다. 어쨌든, 다행 이군. –

0

브라우저 몹 프록시 개체와 셀렌 프록시 개체를 혼동스럽게합니다.

프록시 변수 proxy은 브라우저가 연결할 실제 프록시입니다.

seleniumProxy 변수는 브라우저의 프록시 설정을 나타내는 개체입니다.

"trustAllSSLCertificates"를 프록시 서버의 주소로 사용하도록 브라우저에 알리는 중입니다. 이로 인해 오류가 발생합니다. 대신 browsermob (proxy)을 trustAllSSLCertificates으로 지정해야하며 sslProxy가 browsermob 프록시를 참조해야합니다.

은과 같이 프록시를 시작

:

public void startProxy() { 
     proxy = new BrowserMobProxyServer(); 
     proxy.setTrustAllServers(true); 
     proxy.start(9091); 
} 

시작을 운전자과 같이 :

public void startBrowserWithProxy() { 
     Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); 
     seleniumProxy.setSslProxy("localhost:" + proxy.getPort()); 
     DesiredCapabilities capabilities = new DesiredCapabilities(); 
     capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); 
     System.setProperty("webdriver.chrome.driver", "C:/Users/Madis/Documents/chromedriver.exe"); 
     WebDriver driver = new ChromeDriver(capabilities); 
} 
+0

여전히 같은 문제입니다. 곧 https 사이트로 이동 한 후 작동이 멈 추면 http 연결에서 정상적으로 작동합니다. –

+0

사과, 원래의 예제에서'''proxy.start (9091);''명령을 놓쳤습니다. 어쨌든 프록시를 시작 했습니까? –

+0

예 프록시를 시작했습니다. https를 사용하지 않는 웹 사이트에서 사용할 때 제대로 작동합니다. 먼저 일부 인증서를 설치해야합니까? –

2

당신은 셀레늄 프록시 개체의 sslProxy을 지정할 필요가 없습니다. ClientUtil.createSeleniumProxy이이 작업을 수행하고 의 경우 대부분 인 경우 간단한 기본 값 (InetAddress.getLocalHost() 사용)을 선택하면 HTTP에서 작동하는 경우 HTTPS에서도 작동합니다. 명심해야 할

몇 가지 : 당신도, 크롬에 (인증서 오류를 무시하도록 브라우저를 말해 --ignore-인증서 오류를 사용하지 않는

  1. 당신은 브라우저에서 SSL 경고를 받게됩니다 명령 행 플래그)를 사용하거나 브라우저의 신뢰 저장소에 BMP CA을 설치하십시오 (Windows의 경우, Windows 트러스트 스토어에 설치해야 함).
  2. Chrome 및 OS 버전에 따라 명령 줄 옵션을 사용하여 대체 user-data-dir을 지정해야 할 수 있습니다. 예 : --user-data-dir=/tmp/insecurechrome.
  3. BMP에는 신뢰할 수있는 인증서 소스 (Java 신뢰 저장소 + Mozilla의 최근 목록)가 있으므로 개인 CA에서 발급 한 인증서로 내부 웹 사이트에 연결하려는 경우 BMP에 신뢰 개인 CA 또는 .setTrustAllServers (true)를 사용하여 인증서 유효성 검사를 건너 뜁니다.
  4. 프록시는 createSeleniumProxy()를 호출하기 전에 .start (...)를 사용하여 시작해야합니다. 이 모든 일을 결합

, 코드를 다음과 같이 보일 것입니다 :

BrowserMobProxy proxy = new BrowserMobProxyServer(); 
proxy.setTrustAllServers(true); 
proxy.start(9091); 

// get the Selenium proxy object 
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); 
// NOTE: there is no call to .setSslProxy() here 

// configure it as a desired capability 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); 
System.setProperty("webdriver.chrome.driver", "C:/Users/Madis/Documents/chromedriver.exe"); 

ChromeOptions options = new ChromeOptions(); 
options.addArgument("--ignore-certificate-errors"); 
// replace 'somedirectory' with a suitable temp dir on your filesystem 
options.addArgument("--user-data-dir=somedirectory"); 
capabilities.setCapability(ChromeOptions.CAPABILITY, options); 

WebDriver driver = new ChromeDriver(capabilities); 

// [...] 
+0

붙여 넣기 복사하고 작동하지 않는 것 같습니다. 내 것과 같은 문제. https를 사용하는 사이트는로드되지 않습니다. –

+0

도움 주셔서 감사합니다. 나는 browsermob에 대한 모든 디버그 로그를 얻은 후에 작동하도록했습니다. Google 구아바 의존성을 추가하면 문제가 해결되었습니다. –

1

이 문제가 발생했습니다. 수많은 시도가 있은 후에 회사 프록시에 연결되어 있다면 setmitmManager와 업스트림 프록시를 추가해야한다는 것을 알아야합니다. 그것은 나를 위해 일했습니다.

다음은 예제 코드입니다.

BrowserMobProxy proxy = new BrowserMobProxyServer(); 
proxy.setTrustAllServers(true); 

//Add below line if you are under corporate proxy. 
proxy.setChainedProxy(new InetSocketAddress("XXX.XXX.com", 8080)); 
proxy.setMitmManager(ImpersonatingMitmManager.builder().trustAllServers(true).build()); 
proxy.start(9091); 

// get the Selenium proxy object 
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); 

// configure it as a desired capability 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); 
System.setProperty("webdriver.chrome.driver","C:/Users/Madis/Documents/chromedriver.exe"); 


WebDriver driver = new ChromeDriver(capabilities); 
// your code to start, get har