如何在Selenium服务器上独立运行任何(Chrome,Firefox,PhantomJS)浏览器?
我的问题或问题=我无法在selenium远程服务器上运行任何浏览器,该如何解决?
My Question or Problem = I cannot run any browser with selenium remote server, how do I fix this?
我的环境:
- 操作系统Windows 10
- 我正在Java 1.8中使用eclipse(版本:Neon发行版(4.6.0))
- 硒Web驱动程序3.0.0
- selenium-server-standalone-3.0.1.jar
我在cmd中启动selenium-server-standalone. ("selenium-server-standalone-3.0.1.jar"文件存储在我的C盘上的Utility文件夹中)
I start selenium-server-standalone in cmd. ("selenium-server-standalone-3.0.1.jar" the file is stored in the utilities folder on my c drive )
C:\Windows\system32> cd\
C:\> cd utilities
C:\Utilities> java -jar selenium-server-standalone-3.0.1.jar
然后selenium-server-standalone启动,一切看起来很好
Then selenium-server-standalone starts and everything looks fine
运行测试时
Eclipse提供了此错误:
Eclipse provides this error:
Feb 09, 2017 10:36:35 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Feb 09, 2017 10:36:35 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Feb 09, 2017 10:36:36 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'MWLTSHAUNCR', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: RemoteWebDriver
在cmd中,我收到此错误:
In cmd I received this error:
对于我添加的remoteDriver部分,我的代码看起来像这样.我已经包含了类和构造函数
My code looks something like this for the remoteDriver part that I have added. I have included the class and constructor
public class browser {
private browser (WebDriver driver){
browser.driver = driver;
}
public static void runRemoteDriver(){
try {
WebDriver webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
new browser (webDriver);
} catch (Exception e) {
e.printStackTrace();
}
}
}
我认为您缺少driver.exe文件的路径.您有两种选择:
I think you are missing the path for your driver.exe file. You have two options:
1.您可以按照通常的方式使用 System.setProperty().
1.you can either use System.setProperty(), in the way you do generally.
2.您可以使用如下所示的路径启动RemoteDriver.
2.you can start the RemoteDriver using the path as shown below.
java -Dphantomjs.binary.path=phantomjs.exe -jar selenium-server-standalone-3.4.0.jar
这行代码负责建立连接.
and this line of code is responsible for establishing the connection.
WebDriver webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());