【问题标题】:AssertionError { state: 'pending' }AssertionError {状态:'待定'}
【发布时间】:2016-11-07 09:58:34
【问题描述】:

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

Mocha – 测试运行器

Chai – 断言库

webdriverio – 浏览器控件绑定

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

PhantomJS - 快速无头浏览器

所以我启动了一个像这样的 selenium 服务器

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)

有什么想法我做错了吗??

【问题讨论】:

  • 在你的 wdio 配置文件中,你有 'sync: true,' 吗?
  • 这个问题解决了吗?

标签: javascript selenium mocha.js chai webdriver-io


【解决方案1】:

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

要解决这个问题,您需要使用 Chai 的“as-promised”插件。 The official site has a page 详细说明如何为您进行此设置。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2014-06-16
      • 2012-03-14
      • 2013-10-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多