【问题标题】:How to test tooltip text with mocha, webdriver-io and phantomjs?如何使用 mocha、webdriver-io 和 phantomjs 测试工具提示文本?
【发布时间】:2015-08-03 22:39:19
【问题描述】:

我正在使用 webdriver-io 来测试输入表单,如果输入文本不符合指定条件,我想测试工具提示文本的外观。下面是一个尝试但没有成功的方法

var webdriverio = require('webdriverio');
var browser = webdriverio.remote({desiredCapabilities:{browserName: 'phantomjs'} });
...
describe('Test tooltip text', function(){

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

  before(function(){
    // return browser.setValue(key, value);
  });

  it('should display a tooltip text', function(){
    broswer.getHTML('body').then(function(form){
      form.should.contain('message in tooltip')
    });
  });// it block ends

 });// describe block ends
...

此测试将我重定向到没有工具提示的原始表单。当我尝试在 chrome 浏览器中在此输入表单中输入值时,我确实看到了工具提示。我知道在测试中输入的值是正确的,因为我在控制台记录了输入,并且在制表符之后,我看到输入字段样式在 HTML 中显示为红色。我错过了什么?

【问题讨论】:

    标签: selenium phantomjs mocha.js webdriver-io


    【解决方案1】:

    您可以阅读元素的“标题”标签,它只是工具提示。

    【讨论】:

    • 这是一个好的开始。但是没有办法验证工具提示文本本身吗?
    【解决方案2】:

    经过多次尝试,我找到了使用 setTimeout 捕获工具提示文本的解决方案。这是我的测试:

    ... 
    it('should display a tooltip text', function(){
       broswer.getHTML('body').then(function(form, done){
         form.should.contain('message in tooltip');
         setTimeout(done, 1000);
      });
    });// it block ends
    ...
    
    ...
    

    我希望这个解决方案对其他人有帮助!

    【讨论】:

    • 不知道为什么代码部分没有语法高亮!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多