Nightwatch.js不能将字符串变量设置为输入字段? [英] Nightwatch.js cannot set a string variable to an input field?

查看:157
本文介绍了Nightwatch.js不能将字符串变量设置为输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Nightwatch.js测试一些JavaScript代码。我想从输入标签读取一个值,将其增加或减少1,然后将其写回输入标签。因此我编写了这段代码:

  .getValue('#inputConfigReading',function(result){
val = parseInt (result.value);
if(val%2 == 0)
val ++;
else
val--;
val = val +'';
$ b .clearValue('#inputConfigReading')
.setValue('#inputConfigReading',val)

我检查了一下。变量 val 在命令 val = val +''; 之后具有正确的值。但无论如何,当我运行代码Nightwatch将 undefined 写入输入字段时。为什么?

解决方案

Nightwatch正在执行 val 之前的最后两个步骤定义。
最后两步应该在 .getValue 的回调函数中:

 < $ c $ .getValue('#inputConfigReading',function(result){
val = parseInt(result.value);
if(val%2 == 0)
val ++;
else
val--;
val = val +'';
browser.clearValue('#inputConfigReading')
browser.setValue('#inputConfigReading',val )
})


I am testing some JavaScript code with Nightwatch.js. I want to read a value from an input tag, increase or decrease it by 1 and then write it back to the input tag. Therefore I wrote this code:

.getValue('#inputConfigReading', function(result){
    val = parseInt(result.value);
    if (val % 2 == 0)
        val++;
    else
        val--;
    val = val+'';
})
.clearValue('#inputConfigReading')
.setValue('#inputConfigReading', val)

I checked it out. The variable val has the correct value after the command val = val+'';. But anyway when I run the code Nightwatch is writing undefined into the input field. Why?

解决方案

Nightwatch is executing those last two steps before val is defined. Those last two steps should be inside the callback function of .getValue:

.getValue('#inputConfigReading', function(result){
    val = parseInt(result.value);
    if (val % 2 == 0)
        val++;
    else
        val--;
    val = val+'';
    browser.clearValue('#inputConfigReading')
    browser.setValue('#inputConfigReading', val)
})

这篇关于Nightwatch.js不能将字符串变量设置为输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆