我可以同时在不同的端口上运行selenium服务器吗?

时间:2015-03-10 08:53:18

标签: java selenium selenium-webdriver webdriver

我看到这个post关于如何在2个不同的端口上运行selenium web驱动器服务器。

我试过这样做:

 java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4445

 java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4444

并运行在端口4445上调用服务器的代码

但我得到了这个例外:

rond-macpro:selenium eladb$ java -Dwebdriver.chrome.driver=./chromedrive -jar selenium-server-standalone-2.44.0.jar -port 4445
17:26:14.740 INFO - Launching a standalone server
17:26:14.780 INFO - Java: Oracle Corporation 24.76-b04
17:26:14.781 INFO - OS: Mac OS X 10.9.5 x86_64
17:26:14.793 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
17:26:14.889 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: MAC
17:26:14.930 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4445/wd/hub
17:26:14.931 INFO - Version Jetty/5.1.x
17:26:14.931 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
17:26:14.932 INFO - Started HttpContext[/selenium-server,/selenium-server]
17:26:14.932 INFO - Started HttpContext[/,/]
17:26:14.969 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@256b8a7a
17:26:14.969 INFO - Started HttpContext[/wd,/wd]
17:26:14.973 INFO - Started SocketListener on 0.0.0.0:4445
17:26:14.973 INFO - Started org.openqa.jetty.jetty.Server@7a112202
17:26:21.139 INFO - Executing: [new session: Capabilities [{platform=ANY, acceptSslCerts=true, browserName=chrome, args=[--enable-logging, --v=1], version=}]])
17:26:21.149 INFO - Creating a new session for Capabilities [{platform=ANY, acceptSslCerts=true, browserName=chrome, args=[--enable-logging, --v=1], version=}]
17:26:23.530 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_76'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:175)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:111)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:88)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:108)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:112)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:172)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:163)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:129)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
    at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
    at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_76'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:69)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:53)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:54)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:214)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:168)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    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.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:59)
    ... 9 more
Caused by: java.lang.IllegalStateException: The driver executable does not exist: /Users/rgoldfar/selenium/./chromedrive
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:139)
    ... 14 more
17:26:23.536 WARN - Exception: The driver executable does not exist: /Users/rgoldfar/selenium/./chromedrive
17:26:23.637 INFO - Executing: [new session: Capabilities [{platform=ANY, acceptSslCerts=true, browserName=chrome, args=[--enable-logging, --v=1], version=}]])
17:26:23.638 INFO - Creating a new session for Capabilities [{platform=ANY, acceptSslCerts=true, browserName=chrome, args=[--enable-logging, --v=1], version=}]
17:26:23.639 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_76'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:175)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:111)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:88)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:108)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:112)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:172)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:163)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:129)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
    at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
    at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException

顺便说一下,服务器可以在同一时间处理来自多个客户端的请求到一个端口吗?或者我是否需要为每个客户提供不同的端口?

2 个答案:

答案 0 :(得分:3)

是可以在不同端口上运行服务器,服务器可以处理来自同一端口的服务器客户端的请求。你想在这里设置集线器/节点设置吗?

HUB:

java -jar selenium-server-standalone-2.44.0.jar -role hub -port 4444

节点:

java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register -port 5557

答案 1 :(得分:0)

看起来你有错字。

我想它应该是

java  -jar selenium-server-standalone-2.44.0.jar -Dwebdriver.chrome.driver=./chromedriver -port 4445

你错过

中的 r
-Dwebdriver.chrome.driver=./chromedriver

您可能希望通过命令行分解。