AssertionError {state:'pending'}

时间:2016-11-07 09:58:35

标签: javascript selenium mocha chai webdriver-io

我尝试使用不同堆栈的汇编:

Mocha - 测试跑步者

Chai - 断言库

webdriverio - 浏览器控件绑定

Selenium - 浏览器抽象和运行工厂

PhantomJS - 快速无头浏览器

所以我发布了像这样的硒服务器

java -jar selenium-server.jar

我就像这样启动我的测试

 mocha test.js -t 10000

这是我的 test.js

var webdriverio = require('webdriverio');
var options = { desiredCapabilities: { browserName: 'phantomjs' } };
var client = webdriverio.remote(options);


describe('Test example.com', function(){
    before(function(done) {
        client.init().url('/* my website */');
        done();
        //client.pause(5000);
        var chai = require('chai');
        global.expect = chai.expect;
        chai.Should();

    });


    describe('Check homepage', function(){
        it('should wait 3 secondes', function() {
            client.pause(3000);
        });

        it('should see the correct title', function() {
            client.waitForValue('#logoHeaderNav', 3000);
            client.url('/* my website */');
            client.getTitle().should.be.equal('/*my title*/');

        });
    });

    after(function(done) {
    client.end();
    done();
    });
});

我得到的结果是:

# mocha test.js -t 10000


  Test example.com
    Check homepage
      ✓ should wait 3 secondes
      1) should see the correct title


  1 passing (108ms)
  1 failing

  1) Test example.com Check homepage should see the correct title:
     AssertionError: expected { state: 'pending' } to equal '/*my title */'
      at Context.<anonymous> (test.js:90:35)

我做错了什么想法?

2 个答案:

答案 0 :(得分:3)

WebdriverIO命令都返回promises,这就是错误消息中的{ state: 'pending' }

为了解决这个问题,你会想要使用Chai&#34;作为承诺&#34;插入。 The official site has a page详细说明了如何为您设置此功能。

答案 1 :(得分:-1)

尝试删除client.waitForValue(&#39; #logoHeaderNav&#39;,3000);声明并查看它是否有效。

相关问题