从Gradle运行Selenium webdriver-manager

时间:2015-10-11 13:56:14

标签: selenium selenium-webdriver gradle protractor

我正在尝试从Gradle启动Selenium以运行Protractor测试。

这是我的Gradle脚本:

//main task to run protractor tests
task uiTests << {
    println "Starting protractor tests"
}

//start Selenium server
task startSelenium << {
    println "Starting Selenium..."
    ant.exec(executable: '/bin/bash', spawn: true) {
        arg(value:'webdriver-manager')
        arg(value:'start')
    }
}

//run protractor
task runProtractor(type: Exec) {
    commandLine 'protractor', 'bignibou-client/protractor.conf.js'
}

//start selenium, then run protractor
uiTests.dependsOn([startSelenium, runProtractor])

但是,输出似乎表明Selenium进程尚未启动:

 :runProtractor
    Using the selenium server at http://localhost:4444/wd/hub
    [launcher] Running 1 instances of WebDriver

/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:172
      callback(new Error(message));
               ^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:172:16)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:259:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1250:8)
    at doNTCallback2 (node.js:429:9)
    at process._tickCallback (node.js:343:17)
From: Task: WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
    at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
    at [object Object].Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:445:22)
    at [object Object].DriverProvider.getNewDriver (/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
    at [object Object].Runner.createBrowser (/usr/local/lib/node_modules/protractor/lib/runner.js:182:37)
    at /usr/local/lib/node_modules/protractor/lib/runner.js:263:21
    at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
    at /usr/local/lib/node_modules/protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1
:runProtractor FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':runProtractor'.
> Process 'command 'protractor'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

有人可以提供明智的提示和指导吗?

1 个答案:

答案 0 :(得分:3)

通过直接引用webdriver-manager脚本,如下所示排序问题:

//main task to run protractor tests
task uiTests << {
    println "Starting protractor tests"
}

//start Selenium server
task startSelenium << {
    println "Starting Selenium..."
    ant.exec(executable: 'webdriver-manager', spawn: true) {//CHANGED!!
        arg(value: 'start')
    }
}

//run protractor
task runProtractor(type: Exec) {
    commandLine 'protractor', 'bignibou-client/protractor.conf.js'
}

//start selenium, then run protractor
uiTests.dependsOn([startSelenium, runProtractor])