大佬教程收集整理的这篇文章主要介绍了node.js – 使用Nightwatch.js启动Selenium Server,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
StarTing SELEnium server... started - PID: 1760 [Test] Test Suite ================= Running: demoTestGoogle Error retrieving a new session from the SELEnium server Error: connect ECONNREFUSED 127.0.0.1:8080 at Object.exports._errnoException (util.js:856:11) at exports._exceptionWithHostPort (util.js:879:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14) Connection refused! Is SELEnium server started? Process finished with exit code 1
13:43:03.394 INFO - Launching a standalone SELEnium Server 13:43:03.474 INFO - Java: Oracle Corporation 25.73-b02 13:43:03.474 INFO - OS: Windows 7 6.1 amd64 13:43:03.483 INFO - v2.52.0,with Core v2.52.0. Built from revision 4c2593c 13:43:03.530 INFO - Driver class not found: com.opera.core.systems.OperaDriver 13:43:03.530 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered 13:43:03.536 INFO - Driver provider org.openqa.SELEnium.safari.SafariDriver registration is skipped: registration capabilities Capabilities [{BrowserName=safari,version=,platform=MAC}] does not match the current platform VISTA 13:43:03.665 INFO - RemoteWebDriver instances should connect to: @R_489_10107@://127.0.0.1:4444/wd/hub 13:43:03.665 INFO - SELEnium Server is up and running
这是我的nightwatch.json文件
{ "src_folders": [ "tests" ],"output_folder": "reports","custom_commands_path": "","custom_assertions_path": "","page_objects_path": "","globals_path": "","SELEnium": { "start_process": true,"server_path": "./bin/SELEnium-server-standalone-jar/jar/SELEnium-server-standalone-2.52.0.jar","start_session" : true,"log_path": "","host": "","port": 4444,"cli_args": { "webdriver.chrome.driver": "","webdriver.ie.driver": "" } },"test_setTings": { "default": { "launch_url": "@R_489_10107@://localhost","SELEnium_port": 8080,"SELEnium_host": "localhost","silent": true,"screenshots": { "enabled": false,"path": "" },"desiredCapabilities": { "browserName": "firefox","javascriptEnabled": true,"acceptSslCerts": true } },"chrome": { "desiredCapabilities": { "browserName": "chrome","acceptSslCerts": true } } } }
编辑:添加了demoTestGoogle,我有一个nightwatch.js文件,我在其中运行,然后运行demoTestGoogle函数.
运行demoTestGoogle的nightwatch.js
require('nightwatch/bin/runner.js');
this.demoTestGoogle = function (browser) { browser .url('@R_489_10107@://www.google.com') .waitForElementVisible('body',1000) .SETVALue('input[type=text]','nightwatch') .waitForElementVisible('button[name=btnG]',1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#main','The Night Watch') .end(); };
这是一个简单的例子,我从GitHub源代码修改了它的测试启动SELEnium.确保首先在项目中安装依赖项:
npm install --save-dev nightwatch chromedriver SELEnium-server
然后用.js替换那个JSON文件,也许命名为nightwatch.conf.js,并注意配置文件中SELEnium键下的配置选项:
nightwatch.conf.js
const SELEniumServer = require("SELEnium-server"); const chromedriver = require("chromedriver"); const SCREENSHOT_PATH = "./screenshots/"; module.exports = { "src_folders": [ "tests/e2e" ],"output_folder": "./reports",// tells nightwatch to start/stop the SELEnium process "server_path": SELEniumServer.path,"host": "127.0.0.1",// standard SELEnium port "cli_args": { "webdriver.chrome.driver" : chromedriver.path } },"test_setTings": { "default": { "screenshots": { "enabled": true,// if you want to keep screenshots "path": SCREENSHOT_PATH // save screenshots here },"globals": { "waitForConditionTimeout": 5000 // set a (default) timeout period,maybe 5s },"desiredCapabilities": { // use Chrome as the default browser for tests "browserName": "chrome" } },"javascriptEnabled": true } } } } function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/ return count < 10 ? '0' + count : count.toString(); } var FILECOUNT = 0; // "global" screenshot file count /** * The default is to save screenshots to the root of your project even though * there is a screenshots path in the config object above! ... so we need a * function that returns the correct path for storing our screenshots. * While we're at it,we are adding some Meta-data to the filename,specifically * the Platform/Browser where the test was run and the test (filE) name. */ function imgpath (browser) { var a = browser.options.desiredCapabilities; var Meta = [a.platform]; Meta.push(a.browserName ? a.browserName : 'any'); Meta.push(a.version ? a.version : 'any'); Meta.push(a.Name); // this is the test filename so always exists. var Metadata = Meta.join('~').toLowerCase().replace(/ /g,''); return SCREENSHOT_PATH + Metadata + '_' + padLeft(FILECOUNT++) + '_'; } module.exports.imgpath = imgpath; module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
我用来运行它的命令就是这个,使用本地安装的nightwatch版本:
nightwatch --config nightwatch.conf.js
以上是大佬教程为你收集整理的node.js – 使用Nightwatch.js启动Selenium Server全部内容,希望文章能够帮你解决node.js – 使用Nightwatch.js启动Selenium Server所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。