2016-06-21 101 views
0

我無法創建BMP以從我在Sauce實驗室中運行的Java測試中捕獲流量。有沒有人成功完成這項任務?設置browsermobproxy以便在appium和醬汁實驗室中成功運行

這裏是我的代碼〔實施例:

public class AppiumTestBase { 

    BrowserMobProxy proxy; 

    public RemoteWebDriver createSauceDriver() throws Exception { 
    String sauceUserName = "userName"; 
    String sauceAccessKey = "myKey"; 

    proxy = new BrowserMobProxyServer(); 
    proxy.start(); 

    int port = proxy.getPort(); 


    DesiredCapabilities caps = DesiredCapabilities.android(); 
    caps.setCapability("deviceName", "Android Emulator"); 
    caps.setCapability("deviceType", "phone"); 
    caps.setCapability("deviceOrientation", "portrait"); 
    caps.setCapability("browserName", ""); 
    caps.setCapability("platformVersion", "5.1"); 
    caps.setCapability("platformName", "Android"); 
    caps.setCapability("app", "sauce-storage:app.zip"); 
    caps.setCapability("app-package", "myPackage"); 
    caps.setCapability("app-activity", "myOpenActivity"); 

    //get/set test name 
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); 
    caps.setCapability("name", stackTrace[2].getMethodName()); 


    RemoteWebDriver rd = new RemoteWebDriver(new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:"+port+"/wd/hub", sauceUserName, sauceAccessKey)), 
      caps); 

    return rd; 
} 

@Test 
public void sauceIt() throws Exception { 

    RemoteWebDriver d = createSauceDriver(); 

    proxy.newHar("New HAR"); 

    d.findElement(By.id("main_button")).click(); 

    Thread.sleep(4000); 
    Har h = proxy.getHar(); 
    File f = new File("/Users/me/Desktop/sauceExample"); 
    h.writeTo(f); 

    d.quit(); 

} 

org.openqa.selenium.remote.UnreachableBrowserException:無法啓動新的會話。可能的原因是遠程服務器的地址無效或瀏覽器啓動失敗。

當我在端口80上啓動RemoteWebDriver時,測試將實際運行,但不會捕獲任何流量。

例如

 RemoteWebDriver rd = new RemoteWebDriver(new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", sauceUserName, sauceAccessKey)), 
      caps); 

回答

0

如果有人遇到這種尋找一個答案 - 你必須開始醬油通過BMP連接,然後通過API

@Test 
public void sauceIt() throws Exception { 

    RemoteWebDriver d = createSauceDriver(); 

    //start new har 
    put("http://localhost:9000/proxy/9091/har"); 

    d.findElement(By.id("menu_footer")).click(); 

    Response har = get("http://localhost:9000/proxy/9091/har"); 
    String harStr = har.asString(); 
    System.out.println(harStr); 

    d.quit(); 
+0

嗨訪問代理,我期待在這個例子中,並想知道這意味着什麼://開始新的har put(「http:// localhost:9000/proxy/9091/har」);它是dput嗎?你也有在你的控制檯運行sauceconnect和bmp嗎?謝謝 – Aqua267

+0

你好 - 事實並非如此。 'd'是遠程web驅動程序(移動應用程序)的實例,PUT是啓動har「錄製」的代理的HTTP請求。請讓我知道,如果我可以進一步澄清 –

+0

謝謝。我仍在尋求幫助。你開始在443端口連接醬嗎? http:// {0}:{1} @ ondemand.saucelabs.com:「+ port +」/ wd/hub或9091? – Aqua267

0
`public RemoteWebDriver createSauceDriver() throws Exception { 
    String sauceUserName = "uname"; 
    String sauceAccessKey = "key"; 

    proxy = new BrowserMobProxyServer(); 
    proxy.start(9091); 

    int port = proxy.getPort(); 

    System.out.println("bmp listening on port is " + port); 

    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability("platformName", "iOS"); 
    capabilities.setCapability("deviceName", "iPhone 7"); 
    capabilities.setCapability("platformVersion", "10.2"); 

    capabilities.setCapability("app", "sauce-storage:TestApp.app.zip"); 
    capabilities.setCapability("browserName", ""); 
    capabilities.setCapability("deviceOrientation", "portrait"); 
    capabilities.setCapability("autoAcceptAlerts", true); 
    capabilities.setCapability("appiumVersion", "1.6.3"); 
    capabilities.setCapability("name", "SDK_Sauce"); 

    RemoteWebDriver rd = new RemoteWebDriver(new URL(SauceConnectProxy.URL), capabilities); 

    return rd; 
    } 

    @Test 
    public void sauceIt() throws Exception { 

    RemoteWebDriver d = createSauceDriver(); 
    sdkDemoApp = new iOSSdkDemoAppPage(d); 
    //start new har 
    SauceConnectProxy.SavePutCall(); 

    demoApp.click(); 
    demoApp.rotate(); 

    String response = SauceConnectProxy.SaveGetCall(); 
    System.out.println(response); 

    d.quit(); 

    } 
相關問題