- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 selenium-webdriver 并想试用 nightwatch.js 看看它是否更易于使用。我按照说明 here .我决定让 Nightwatch 自动为我启动 selenium 服务器,所以我根据上面提供的链接做了我认为正确的配置。我收到一个我无法弄清楚的错误,输出显示:
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
selenium 调试日志文件是这样说的
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: http://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": "http://localhost",
"selenium_port": 8080,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
编辑:添加了 demoTestGoogle,我有一个 nightwatch.js 文件,我在其中运行然后运行 demoTestGoogle 函数。
运行 demoTestGoogle 的 nightwatch.js
require('nightwatch/bin/runner.js');
在单独的 JS 文件中演示 TestGoogle 函数
this.demoTestGoogle = function (browser) {
browser
.url('http://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();
};
最佳答案
正如 Nightwatch 的伟大指南所建议的那样,dwyl-learn-nightwatch ,您可以将 nightwatch.json 文件替换为 .js 文件,以添加变量、全局变量等功能,甚至在 Selenium 中需要,以便 Nightwatch 可以看到并运行它。
这是我从 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",
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444, // 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"
}
},
"chrome": {
"desiredCapabilities": {
"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 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35730910/
nightwatch.conf.BASIC.js 和nightwatch 框架中的 nightwatch.conf.js。 设置守夜人框架的基本要求是什么 Node js 和 Selenium 最佳答
你如何在 nightwatch 中检查背景图像?如何确保正确加载背景图像?背景图像是使用 css 加载的。 最佳答案 希望这可以帮助: browser.waitForElementVisible('.
我使用 Nightwatch 编写了浏览器自动化测试用例。我还为 headless 测试用例实现了“phantomjs-prebuilt”。当我设置时,我能够为我的所有测试用例创建一个报告'test_
我正在尝试测试待办事项应用程序是否具有正确数量的元素。 文档似乎几乎只处理单个元素,所以我不得不使用 Selenium 协议(protocol)函数。这是否是测试匹配选择器计数的正确方法(在这种情况下
目前在我的 nightwatch.json 中,我已设置好在我的 mac 上运行: { "src_folders" : ["specs"], "output_folder" : "tests/
我正在使用 Nightwatch 并希望监控我的 nightwatch 步骤生成的 http 请求。有没有办法监听发送的请求和收到的响应。我不需要修改它们。 谢谢 马特 最佳答案 是的,有办法。 为了
我想暂停每个测试。 我创建了这个函数: afterEach:function(browser){ browser.pause(2000); }, 但是当我运行测试时,我会得到错误: TypeEr
从这个answer FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("browse
我使用 Nightwatch for e2e,我发现这两个命令有点困惑 给出它们附带的名称和解释。 .waitForElementVisible: 在执行任何其他命令或断言之前,等待给定时间(以毫秒为
我使用 Nightwatch.js 设置了一个简单的 smoketest。他们在本地通过,但在 CircleCI 上失败。 源代码: const WAIT = 1000; const NODE_POR
我有六个测试用例需要运行,但任何时候只有三个测试用例可以在测试目标环境中处于事件状态。当我运行测试时,我想检查是否针对特定情况正确设置了环境。如果没有,我想将测试标记为已跳过。如何在 nightwat
如何贴在床头柜上?我尝试了以下命令: browser.keys([browser.Keys.COMMAND, browser.Keys.v]) 但是该命令不起作用。 理想情况下,我希望可以将复制的文本
我正在尝试在测试中使用launch_url属性,并在将浏览器发送到该URL之前为其添加相对路径。 我知道browser.init();将浏览器发送到launch_url中的地址,但是我想知道是否可以在
我想在(非全屏)模式对话框下方的全屏 div 上执行单击。但是,单击事件似乎自动定位到我的背景 div 的中心,从而触摸了该 div 顶部的内容(模态对话框本身)。 如何指定点击应该发生的位置? 这是
如何在 NightwatchJS 中编写简单的 if/else?如果元素存在,请单击此元素,否则 - 单击另一个元素。 'Test2: click login button': function(cl
我的每个 Nightwatch.js 测试都需要身份验证才能运行,目前我无法通过 cookie 进行身份验证(当然,如果测试填写用户名和密码,它就会登录,但需要时间是这样的) 我有一个工作 PHPSE
我在自动测试和设置 Nightwatch 方面相当陌生,但我已经知道我的自定义命令文件夹迟早会变得笨拙。我看过一些示例 nightwatch.json 文件,这些文件使用数组作为自定义命令路径,但我似
我尝试向 Nightwatch 提供测试数据,但我不知道如何提供。如何为 Nightwatch 测试提供动态测试数据? 我不想将值硬编码到代码中。我想从文件中提供它。 编辑: .setValue('s
在浏览器实际启动之前,我有很多脚本首先运行的测试,这有时会导致测试运行不正确。实际上导致我出现问题的最新情况是 try/catch 表达式,它并没有真正捕捉到某些元素不存在的事实(尽管预计不会存在)。
我正在尝试在 nightwatch 中创建一个自定义命令,该命令在 Postgres 数据库上运行查询并返回结果。查询运行得很好并将结果输出到控制台,但测试的执行随后停止。我不明白回调是如何工作的。如
我是一名优秀的程序员,十分优秀!