我在节点8.9.0上使用selenium-server版本3.0.1和nightwatch版本^0.9.12。我的e2e测试确实运行、单击work和读取DOM工作,但setValue就是没有。
例如,以下测试:
browser
.url("...")
.waitForElementPresent('select[name=foo]', 5000)
.click('select[name=foo] option:nth-child(2)')
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})
.end();将打开url,等待foo并单击第二个选项。它将等待bar,然后失败:
Running: test
✔ Element <select[name=foo]> was present after 24 milliseconds.
✔ Element <input[name=bar]> was present after 28 milliseconds.
✖ Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
at Object.<anonymous> (/test/e2e/specs/test.js:49:21)
FAILED: 1 assertions failed and 2 passed (4.692s)
_________________________________________________
TEST FAILURE: 1 assertions failed, 2 passed. (4.9s)
✖ test
- run through apply process (4.692s)
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""如果我用延迟替换setValue并手动输入一个值,测试就会通过,所以getValue正在工作。
这确实会在其他系统上运行和传递,但是我无法让它自己工作,所以我认为这是一个selenium-server问题。
我已经尝试过许多101个修复,清除npm缓存,重新运行npm install等等。但是除了失败之外,没有其他错误,我如何调试呢?
发布于 2018-03-22 11:41:21
假设您正在尝试使用Chrome进行测试,则需要更新您的ChromeDriver。Chrome 65是最近发布的,较早的ChromeDriver版本显然与它不兼容。
从下载页面下载最新版本。
让夜莺使用它,nightwatch.json -
{
...
"selenium": {
...
"cli_args": {
"webdriver.chrome.driver": "path/to/chromedriver.exe"假设Nightwatch使用它(您可以看到它使用Windows (假设您使用的是Windows )--查找chromedriver.exe的命令行),setValue现在应该再次工作。
发布于 2018-03-22 06:56:38
这个错误说明了一切:
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""在您的代码块中,您已经为标识为'inputname=bar'的WebElement和下一个调用的setValue()导出了wait,成功的如下所示:
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")现在,与此'inputname=bar'相关联的JavaScript将需要一些时间来呈现HTML中的值。但是,在代码块中,您试图过早地访问输入的值(在上一步中)。因此,您的脚本找到<null>作为值。
解决方案
您需要为HTML中的值通过关联的期望导入一个JavaScript子句,如下所示:
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.expect.element('input[name=bar]').to.have.value.that.equals('hello world');
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})https://stackoverflow.com/questions/49419706
复制相似问题