我試圖從Selenium運行Java 7中的BrowserStackLocal實例。我使用的是Windows 10BrowserStackLocal:從源代碼運行BrowserStackLocal二進制文件
我知道,如果你在Java中使用BrowserStackLocal,你需要運行在CMD.EXE下面這行代碼,並把它打開:
BrowserStackLocal.exe --key <pass_key>
但是,相反的在外部執行它,我希望能夠從代碼中打開命令行。
我也在不同的機器上運行BrowserStack代碼,所以我希望能夠相對地調用上述命令(而不是使用絕對路徑)。
於是我運行這段代碼((browserStackLocalPath)是BrowserStackLocal可執行對象和(密鑰)的名稱在通鍵):
// Initializing desired capabilities.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserstack.local", "true");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "50.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "7");
// Initializing command line parameters...
CommandLine cmdLine = new CommandLine("cmd.exe");
cmdLine.addArgument(browserStackLocalPath);
cmdLine.addArgument("--key");
cmdLine.addArgument(key);
DefaultExecutor executor = new DefaultExecutor();
exitValue = executor.execute(cmdLine);
RemoteWebDriver webDriver = new RemoteWebDriver(new
URL(browserStackURL), caps);
...這已經不僅僅是造成了WebDriverException :
org.openqa.selenium.WebDriverException: [browserstack.local] is set to true but local testing through BrowserStack is not connected. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 870 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'rchen-PC', ip: '192.168.11.105', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_80'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
什麼可能丟失任何想法?