我正在使用JAVA + SELENIUM Web驱动程序+浏览器mobproxy + browserstacklocal(嵌入式)
compile 'com.browserstack:browserstack-local-java:1.0.2'
compile 'net.lightbody.bmp:browsermob-core:2.1.5'
在本地可以正常工作,因为我能够拦截api响应并覆盖响应代码(例如200-OK至502-BAD_GATEWAY)
但是,在浏览器堆栈中运行此测试时,它无法正常工作,因为mobproxy似乎没有拦截响应并覆盖该响应。因此断言在测试步骤中失败。其他不依赖mobproxy的测试在browserstack中可以正常工作。
Proxy seleniumProxy = ProxyUtils.getInstance().createSeleniumProxy();
String host=seleniumProxy.getHttpProxy()
.substring(0,seleniumProxy.getHttpProxy().indexOf(":"));
String port=seleniumProxy.getHttpProxy()
.substring(seleniumProxy.getHttpProxy()
.indexOf(":")+1,seleniumProxy.getHttpProxy().length());
browserStackLocalArgs.put("key", <key>);
browserStackLocalArgs.put("localIdentifier", <identifier>);
browserStackLocalArgs.put("forcelocal", "true");
browserStackLocalArgs.put("force", "true");
browserStackLocalArgs.put("forceproxy", "true");
browserStackLocalArgs.put("localProxyHost", host);
browserStackLocalArgs.put("localProxyPort", String.valueOf(port));
browserStackLocalArgs.put("--daemon", "start");
browserStackLocal.start(browserStackLocalArgs);
我同时使用了localProxyHost和-local-proxy-host,但是没有运气。 我还要为浏览器堆栈添加设置功能。</ p>
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability(CapabilityType.PROXY, proxy);
browserStackCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
在执行ps -ef时| grep browserstack它会返回我
505 921 1 0 6:33pm ?? 0:00.86 /Users/ITAS4/.browserstack/BrowserStackLocal -d start sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine -force -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance
505 943 921 0 6:33pm ?? 0:02.29 /Users/ITAS4/.browserstack/BrowserStackLocal sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine-browserstack-fork-0 -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance
505 944 921 0 6:33pm ?? 0:00.79 /Users/ITAS4/.browserstack/BrowserStackLocal sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine-browserstack-fork-1 -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance
505 945 921 0 6:33pm ?? 0:00.80 /Users/ITAS4/.browserstack/BrowserStackLocal sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine-browserstack-fork-2 -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance
505 946 921 0 6:33pm ?? 0:00.79 /Users/ITAS4/.browserstack/BrowserStackLocal sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine-browserstack-fork-3 -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance
505 947 921 0 6:33pm ?? 0:00.80 /Users/ITAS4/.browserstack/BrowserStackLocal sqfXJPx2Hpyp4L -forceproxy -localIdentifier browserstack_local_machine-browserstack-fork-4 -localProxyPort 49676 ---daemon start -forcelocal -localProxyHost CHISIMAC0123.local -daemonInstance