2017-09-08 4 views
0

私はどこからでも探していて、Sauceラボでスクリプトを実行してHARファイルを抽出するためのプロキシを正しく設定する方法については、適切な文書が見つかりませんでした。私は埋め込みモードでBMPを使用していますhttps://github.com/lightbody/browsermob-proxy#using-with-seleniumhttps://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxyと一緒に。私は、手動でBMPを使ってスクリプトを設定して実行することについてのSourceの文書を見つけましたが、スタンドアロンモードでのみ組み込みモードで設定する方法はドキュメントには記載されていません。https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+with+an+Additional+Proxy+Setupここに私の設定です:RemoteWebDriver/Sauce Labs/Sauce ConnectでBrowserMobProxy/Selenium Proxyを正しく設定するにはどうすればよいですか?

私のPACファイルをバックアップします。ここ

package com.grainger.Framework; 

import java.io.File; 
import java.io.IOException; 
import java.net.Inet4Address; 
import java.net.UnknownHostException; 

import org.apache.log4j.Logger; 
import org.openqa.selenium.Proxy; 
import org.openqa.selenium.remote.CapabilityType; 
import org.openqa.selenium.remote.DesiredCapabilities; 

import com.grainger.Automation.Utilities; 
import com.grainger.Build.BuildVariables; 

import net.lightbody.bmp.BrowserMobProxy; 
import net.lightbody.bmp.BrowserMobProxyServer; 
import net.lightbody.bmp.client.ClientUtil; 
import net.lightbody.bmp.core.har.Har; 
import net.lightbody.bmp.proxy.CaptureType; 

public class BrowserMobProxyImpl { 
    public static Logger log = Logger.getLogger(BrowserMobProxyImpl.class.getName()); 
    private static BrowserMobProxy MOB_PROXY_SERVER; 
    private static Proxy SELENIUM_PROXY; 

    /** 
    * @author xsxg091 
    * @return 
    */ 
    public static void startBrowserMobProxyServer(){ 
     // start the proxy 
     MOB_PROXY_SERVER = getProxyServer(); 
     // get the Selenium proxy object 
     SELENIUM_PROXY = getSeleniumProxy(MOB_PROXY_SERVER); 
    } 

    /** 
    * @author xsxg091 
    * @return 
    */ 
    public static BrowserMobProxy getProxyServer() { 
     BrowserMobProxy proxy = new BrowserMobProxyServer(); 
     proxy.setTrustAllServers(true); 
     proxy.start(9090); 
     return proxy; 
    } 

    /** 
    * @author xsxg091 
    * @param proxyServer 
    * @return 
    */ 
    public static Proxy getSeleniumProxy(BrowserMobProxy proxyServer) { 
     Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);; 
     try { 
      String hostIp = Inet4Address.getLocalHost().getHostAddress(); 
      seleniumProxy.setHttpProxy(hostIp + ":" + Integer.toString(9091)); 
      seleniumProxy.setSslProxy(hostIp + ":" + Integer.toString(9091)); 
      seleniumProxy.setAutodetect(false); 
     } catch (UnknownHostException e) { 
      log.error("Error initializing Selenium Proxy"); 
     } 
     return seleniumProxy; 
    } 

    /** 
    * @author xsxg091 
    * @param tcName 
    * @param capabilities 
    */ 
    public static void setSeleniumProxy(DesiredCapabilities capabilities){ 
     if(BuildVariables.amICapturingNetworkTraffic()){ 
      capabilities.setCapability(CapabilityType.PROXY, SELENIUM_PROXY); 
     } 
    } 

    /** 
    * @author xsxg091 
    * @param tcName 
    * @param capabilities 
    */ 
    public static void stopBrowserMobProxyServer(){ 
     MOB_PROXY_SERVER.stop(); 
    } 

    /** 
    * @author xsxg091 
    * @return 
    */ 
    public static void getHarFile(String fileName) { 
     // enable more detailed HAR capture, if desired (see CaptureType for the complete list) 
     MOB_PROXY_SERVER.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT); 
     MOB_PROXY_SERVER.newHar(fileName); 
     try { 
      // get the HAR data 
      Har pageHarFile = MOB_PROXY_SERVER.getHar(); 
      File harFile = new File(Utilities.getWorkSpace()+"//"+fileName+".har"); 
      pageHarFile.writeTo(harFile); 
     } catch (IOException e) { 
      log.error("Unable to store Har File"); 
     } 
    } 
} 

function FindProxyForURL(url, host) { 
    if (shExpMatch(host, "*.miso.saucelabs.com") || 
     shExpMatch(host, "saucelabs.com")) { 
     // KGP and REST connections. Another proxy can also be specified. 
     return "DIRECT"; 
    } 

    // Test HTTP traffic, route it through the local BrowserMob proxy. 
    return "PROXY localhost:9091"; 
} 

BMPの設定は、私は私のソースのトンネルをキックオフするために使用するコマンドです

bin/sc -u ****** -k *********** -i Tunnel_Testing -v --pac file:///<path-to-pac-file>/BrowserMobProxy/browserMob.js 

I lsofを実行すると、ポート9090は積極的にリスニングしていますが、組み込みモードでは9091が表示されません。しかし、スタンドアロンモードで実行すると、両方のポートを見ることができ、すべてがSauceラボで完全に機能します。私は組み込みモードで実行したときに私はこれを参照してください。

enter image description here

私が間違って何をしているのですか?どんな助けでも大歓迎です。何かが不明な場合は、私に教えてください!

ありがとうございます。

答えて

0

私はそれを理解しました。バージョン2.1.4ではバグだったことが分かります。私がバージョン2.1.5にアップグレードしたとき、すべてが正常に動作しました。

関連する問題