如何使用 webdriverio、mocha 和 phantomjs 测试将字段设置为空字符串?

How to test setting a field to empty string using webdriverio, mocha and phantomjs?

我正在使用 webdriverio、mocha 和 phantomjs 测试当用户未在字段中输入任何内容时工具提示的外观。下面是测试代码:

// failing test
describe ('Test appearance of a tooltip upon entering nothing', function(){
  before(function(){
    return browser.url(site);
  });

  before(function(){
    return browser.setValue('#id_field1', '', 'tab')// mimicking users entering nothing
  });

  it('should notify users via a tooltip "Enter a valid lotno"', function(){
    return browser.getHTML('body')
      .then(function(form, done){
        return form.should.contain('Enter a valid lotno');
          setTimeout(done, 1000);
      });
    }); // it block ends here
  });// describe block ends for tooltip tests

这不显示工具提示文本。

我有另一个测试,如果用户输入了错误的值,它应该会显示一个工具提示文本,这会按预期工作。以下是通过测试:

// passing test
describe ('Test appearance of a tooltip upon entering non numbers', function(){

  before(function(){
    return browser.url(site);
  });

  before(function(){
    return browser.setValue('#id_field1', 'JKJK', 'tab')// mimicking users entering non numbers
  });

  it('should notify users via a tooltip "Numbers only please"', function(){
    return browser.getHTML('body')
      .then(function(form, done){
        return form.should.contain('Numbers only please');
          setTimeout(done, 1000);
      });
  }); // it block ends here
});// describe block ends for tooltip tests

如何测试用户什么都不输入并显示工具提示?当我直接在站点中测试这些步骤时,两个工具提示均按预期显示。

我会尝试以下操作:

before(function(){
    return browser.setValue('#id_field1', ['', 'Tab']);
});

显然 setValue 的用法支持发送值数组:https://github.com/webdriverio/webdriverio/issues/84. Alternatively you could use the keys command. http://webdriver.io/api/protocol/keys.html