问题
My Question or Problem = I cannot run any browser with selenium remote server, how do I fix this?
My environment:
- Operating System Windows 10
- I'm using eclipse(Version: Neon Release (4.6.0)) with java 1.8
- selenium Web driver 3.0.0
- selenium-server-standalone-3.0.1.jar
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
Then selenium-server-standalone starts and everything looks fine
When I run my tests
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
In cmd I received this error:
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();
}
}
}
回答1:
I copied all the driver to folder where I store the "selenium-server-standalone-3.0.1.jar" file. Then it worked!!!
I started server with cmd command:
java -jar selenium-server-standalone-3.0.1.jar
then in you code you must specify which browser you want to run for example:
WebDriver webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
WebDriver webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.chrome());
WebDriver webDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.phantomjs());
回答2:
I think you are missing the path for your driver.exe file. You have two options:
1.you can either use System.setProperty(), in the way you do generally.
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());
来源:https://stackoverflow.com/questions/42132165/how-to-run-any-chrome-firefox-phantomjs-browser-in-selenium-server-standalon