通过selenium网格在多个节点(os平台)中运行量角器测试脚本

时间:2016-08-31 21:09:34

标签: protractor selenium-grid2

我目前正在尝试使用selenium网格运行Protractor测试脚本。我的目标是将Protractor测试脚本分发到在不同风格的OS下运行的多个节点。它还应该并行运行测试脚本的不同部分以节省执行时间。当我使用webdriver-manager为多个实例分发测试时,当前设置有效,但webdriver-manager只允许我使用一个节点。我知道用selenium网格可以克服这个问题,但我有以下错误测试控制台:

node_modules/selenium-webdriver/error.js:26
  constructor(opt_error) {
                         ^
WebDriverError: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at WebDriverError (./node_modules/selenium-webdriver/error.js:26:26)
    at Object.checkLegacyResponse (./node_modules/selenium-webdriver/error.js:580:13)
    at ./node_modules/selenium-webdriver/lib/webdriver.js:64:13
    at Promise.invokeCallback_ (./node_modules/selenium-webdriver/lib/promise.js:1329:14)
    at TaskQueue.execute_ (./node_modules/selenium-webdriver/lib/promise.js:2790:14)
    at TaskQueue.executeNext_ (./node_modules/selenium-webdriver/lib/promise.js:2773:21)
    at ./node_modules/selenium-webdriver/lib/promise.js:2652:27
    at ./node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at acquireSession (./node_modules/selenium-webdriver/lib/webdriver.js:62:22)
    at Function.createSession (./node_modules/selenium-webdriver/lib/webdriver.js:295:12)
    at Builder.build (./node_modules/selenium-webdriver/builder.js:458:24)
    at [object Object].DriverProvider.getNewDriver (./node_modules/protractor/built/driverProviders/driverProvider.js:42:27)
    at [object Object].Runner.createBrowser (./node_modules/protractor/built/runner.js:203:37)
    at ./node_modules/protractor/built/runner.js:293:21
    at _fulfilled (./node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (./node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (./node_modules/q/q.js:796:13)
    at ./node_modules/q/q.js:556:49
[launcher] Process exited with error code 1

此外,我注册的selenium节点抱怨以下消息:

$ java -jar /Users/user/Desktop/selenium-server-standalone-2.52.0.jar   -role node -hub http://localhost:4444/grid/register Dwebdriver.chrome.driver="./node_modules/protractor/selenium/chromedriver_2.21" -browser "browserName=chrome,version=ANY,platform=MAC,maxInstances=20" 
14:40:17.078 INFO - Launching a Selenium Grid node
14:40:17.126 INFO - Adding browserName=chrome,version=ANY,platform=MAC,maxInstances=20
14:40:17.515 INFO - Java: Oracle Corporation 25.74-b02
14:40:17.515 INFO - OS: Mac OS X 10.11.6 x86_64
14:40:17.521 INFO - v2.52.0, with Core v2.52.0. Built from revision 4c2593c
14:40:17.570 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
14:40:17.570 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
14:40:17.570 INFO - Driver class not found: com.opera.core.systems.OperaDriver
14:40:17.570 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
14:40:17.630 INFO - Selenium Grid node is up and ready to register to the hub
14:40:17.650 INFO - Starting auto registration thread. Will try to register every 5000 ms.
14:40:17.650 INFO - Registering the node to the hub: http://localhost:4444/grid/register
14:40:17.669 INFO - The node is registered to the hub and ready to use
14:41:32.968 INFO - Executing: [new session: Capabilities [{rootElement=*[ng-app], count=1, browserName=chrome, maxInstances=4, shardTestFiles=true}]])
14:41:32.977 INFO - Creating a new session for Capabilities [{rootElement=*[ng-app], count=1, browserName=chrome, maxInstances=4, shardTestFiles=true}]
14:41:32.998 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
System info: host: 'user-M-C19J', ip: '10.128.164.26', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_74'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:124)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:79)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:202)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:164)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:130)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    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.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
System info: host: 'user-M-C19J', ip: '10.128.164.26', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_74'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    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:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
    ... 9 more
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
    at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:138)
    ... 14 more
14:41:33.002 WARN - Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

这是我目前的配置:

seleniumAddress: 'http://localhost:4444/wd/hub',
chromeDriver: './node_modules/protractor/selenium/chromedriver_2.21',
capabilities: {
'rootElement': '*[ng-app]',
'browserName': 'chrome', // chrome, firefox, or phantomjs
'shardTestFiles': true,
'maxInstances': 3  
}

我运行以下命令行来启动集线器:

java -jar /Users/xxx/selenium-server-standalone-3.0.0-beta2.jar -role hub

以下是运行节点:

java -jar /Users/xxx/selenium-server-standalone-3.0.0-beta2.jar -role node -hub http://localhost:4444/grid/register

Chrome驱动程序位于:/node_modules/protractor/selenium/chromedriver_2.21

有没有人用selenium grid成功配置量角器?

1 个答案:

答案 0 :(得分:0)

Webdriver_manager捆绑在npm中作为启动服务器的快速解决方案,并不像Selenium Grid那样是一个全面的解决方案。网格应该用于所有专业的分布式执行环境。 检查此link以获取Julie的回复

Webdriver-Manager没有hub&amp; amp ;;节点

关于使用Selenium Grid的Protractor,我确实使用了本地网格和Sauce Labs。 初始化节点时应该传递chrome驱动程序属性。

  

java -jar /Users/xxx/selenium-server-standalone-3.0.0-beta2.jar -role node -hub http:// *******:4444 / grid / register / -Dwebdriver。 chrome.driver = C:/用户/&LT;&GT; /AppData/Roaming/npm/node_modules/protractor/selenium/chromedriver.exe

量角器Conf - chromedriver选项不通过网格传递,它只适用于webdriver-manager。