【发布时间】:2016-08-04 13:14:12
【问题描述】:
我正在使用 selenium 服务器,node.js 上的 nightwatch 和 selenium 的 phantomjs。我仅将 phantomjs 用于无头浏览器(使用它 selenium 在运行测试时不会以可视方式打开浏览器)。
当我使用 firefox 作为浏览器时,我的基本测试通过了,但当我使用 phantomjs 浏览器时失败了。
我设置了基本的谷歌测试:
module.exports = {
'Demo test Google' : 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', 'Night Watch')
.end();
}
};
并设置 phantomjs 服务器。这是我的 nightwatch.json:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "selenium-server-standalone-2.53.1.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 3001,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 3001,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled": true,
"acceptSslCerts": true,
"phantomjs.binary.path" : "phantomjs.exe"
}
}
}
}
当我将 browserName 设置为“firefox”时,测试通过,“OK。3 个断言通过。”。 但是当是“phantomjs”时,一个通过,一个失败,一个错误:“TEST FAILURE: 1 error during execution, 1 assertions failed, 1 pass. (3.511s)”。
有错误:
在等待元素出现 1000 毫秒时超时。 - 预期“可见”但得到:“未找到”
错误:无法使用 css 选择器定位元素:“input[type=text]”
我手动启动服务器。
我使用最新版本的 phantomjs (2.1.1) 和 1.9.8 进行了测试
编辑:
Selenium 服务器在使用 phantomjs 时也报此错误:
WebElementLocator - _handleLocateCommand - 未找到元素:放弃。
【问题讨论】:
标签: node.js selenium phantomjs nightwatch.js