2017-08-24 130 views
0

環境:
OSX塞拉利昂10.12.6默認瀏覽器Safari瀏覽器/節點V8.4.0/Chrome Canary版60.0.3112.101
節點e2e硒測試:如何設置Chrome硒瀏覽器?

我想測試我的環境下,用硒..但: - 野生動物園開始,需要開始的是Chrome瀏覽器硒 - 得到的錯誤:

> node test/e2e/runner.js 

> Starting dev server... 

Starting to optimize CSS... 
> Listening at http://localhost:8080 

Starting selenium server... started - PID: 32583 

[Test] Test Suite 
===================== 

Running: default e2e tests 

Error retrieving a new session from the selenium server 

Connection refused! Is selenium server started? 
{ value: 
    { stacktrace: 'org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary\n (Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.6 x86_64) 

感謝反饋

**測試/ E2E。文件**

runner.js

// 1. start the dev server using production config 
process.env.NODE_ENV = 'testing' 
var server = require('../../build/dev-server.js') 

server.ready.then(() => { 
    // 2. run the nightwatch test suite against it 
    // to run in additional browsers: 
    // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 
    // 2. add it to the --env flag below 
    // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 
    // For more information on Nightwatch's config file, see 
    // http://nightwatchjs.org/guide#settings-file 
    var opts = process.argv.slice(2) 
    if (opts.indexOf('--config') === -1) { 
    opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 
    } 
    if (opts.indexOf('--env') === -1) { 
    opts = opts.concat(['--env', 'chrome']) 
    } 

    var spawn = require('cross-spawn') 
    var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 

    runner.on('exit', function (code) { 
    server.close() 
    process.exit(code) 
    }) 

    runner.on('error', function (err) { 
    server.close() 
    throw err 
    }) 
}) 

晚上watch.conf.js

require('babel-register') 
var config = require('../../config') 

// http://nightwatchjs.org/gettingstarted#settings-file 
module.exports = { 
    src_folders: ['test/e2e/specs'], 
    output_folder: 'test/e2e/reports', 
    custom_assertions_path: ['test/e2e/custom-assertions'], 

    selenium: { 
    start_process: true, 
    server_path: require('selenium-server').path, 
    host: '127.0.0.1', 
    port: 4444, 
    cli_args: { 
     'webdriver.chrome.driver': require('chromedriver').path 
    } 
    }, 

    test_settings: { 
    default: { 
     selenium_port: 4444, 
     selenium_host: 'localhost', 
     silent: true, 
     globals: { 
     devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) 
     } 
    }, 

    chrome: { 
     desiredCapabilities: { 
     browserName: 'chrome', 
     javascriptEnabled: true, 
     acceptSslCerts: true 
     } 
    }, 

    firefox: { 
     desiredCapabilities: { 
     browserName: 'firefox', 
     javascriptEnabled: true, 
     acceptSslCerts: true 
     } 
    } 
    } 
} 

硒的debug.log

15:21:02.882 INFO - Selenium build info: version: '3.5.0', revision: '8def36e068' 
15:21:02.883 INFO - Launching a standalone Selenium Server 
2017-08-24 15:21:03.095:INFO::main: Logging initialized @2678ms to org.seleniumhq.jetty9.util.log.StdErrLog 
15:21:03.426 INFO - Driver class not found: com.opera.core.systems.OperaDriver 
15:21:03.788 INFO - Driver provider class 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 
15:21:03.789 INFO - Driver provider class org.openqa.selenium.edge.EdgeDriver registration is skipped: 
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC 
15:21:04.032 INFO - Using the passthrough mode handler 
2017-08-24 15:21:04.274:INFO:osjs.Server:main: jetty-9.4.5.v20170502 
2017-08-24 15:21:04.412:WARN:osjs.SecurityHandler:main: [email protected]@3632be31{/,null,STARTING} has uncovered http methods for path:/
2017-08-24 15:21:04.450:INFO:osjsh.ContextHandler:main: Started [email protected]{/,null,AVAILABLE} 
2017-08-24 15:21:04.651:INFO:osjs.AbstractConnector:main: Started [email protected]{HTTP/1.1,[http/1.1]}{0.0.0.0:4444} 
2017-08-24 15:21:04.652:INFO:osjs.Server:main: Started @4235ms 
15:21:04.653 INFO - Selenium Server is up and running 
2017-08-24 15:21:07.820:INFO:osjshC.ROOT:qtp1562557367-10: org.openqa.selenium.remote.server.WebDriverServlet-39aeed2f: Initialising WebDriverServlet 
15:21:08.910 INFO - Binding default provider to: org.openqa.selenium.chrome.ChromeDriverService 
15:21:08.911 INFO - Found handler: [email protected] 
15:21:08.936 INFO - /session: Executing POST on /session (handler: BeginSession) 
15:21:09.058 INFO - Capabilities are: Capabilities {acceptSslCerts=true, name=Test, browserName=chrome, javascriptEnabled=true, platformName=ANY, platform=ANY, } 
15:21:09.060 INFO - Capabilities {acceptSslCerts=true, name=Test, browserName=chrome, javascriptEnabled=true, platformName=ANY, platform=ANY, } matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService) 
15:21:09.087 INFO - Capabilities {acceptSslCerts=true, name=Test, browserName=chrome, javascriptEnabled=true, platformName=ANY, platform=ANY, } matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService) 
Starting ChromeDriver 2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b) on port 2776 
Only local connections are allowed. 
+0

你如何安裝Chrome瀏覽器?使用brew還是直接使用?另外如何chromedriver設置? –

+0

是的..我發現了這個問題,以及如何解決它......我很快就會寫出答案.. 基本上我正在使用鉻金絲雀!默認是Chrome ..所以我需要更新我的夜晚watch.conf .js。鉻驅動程序設置與nom(chromedriver:「^ 2.27.2)謝謝 – erwin

回答

0

我忘了檢查我用於開發的Chrome版本! Chrome Canary版,而不是瀏覽器,所以我需要更新我的夜晚watch.conf.js accordingingly

test_settings: { 
    default: { 
     selenium_port: 4444, 
     selenium_host: 'localhost', 
     silent: true, 
     globals: { 
     devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) 
     } 
    }, 

    chrome: { 
     desiredCapabilities: { 
     browserName: 'chromeCanary', 
     platform: 'MAC', 
     chromeOptions: { 
      binary: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', 
     }, 
     javascriptEnabled: true, 
     acceptSslCerts: true 
     } 
    }, 

    firefox: { 
     desiredCapabilities: { 
     browserName: 'firefox', 
     javascriptEnabled: true, 
     acceptSslCerts: true 
     } 
    } 
    } 

然後我可以運行端到端測試:

> node test/e2e/runner.js 

> Starting dev server... 

Starting to optimize CSS... 
> Listening at http://localhost:8080 

Starting selenium server... started - PID: 36140 

[Test] Test Suite 
===================== 

Running: default e2e tests 
✔ Element <#app> was visible after 185 milliseconds. 
✔ Testing if element <h1> contains text: "Welcome to Your Vue.js App". 
✔ Testing if element <img> has count: 1 

OK. 3 assertions passed. (16.735s)