我无法创建 BMP 来捕获来自 Sauce 实验室中运行的 Java 测试的流量。有没有人成功完成过这个任务?
这是我的示例代码:
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);