【问题标题】:webdriverjs: Expected string got an objectwebdriverjs:预期的字符串有一个对象
【发布时间】:2013-12-23 13:26:42
【问题描述】:

发现 Mocha 和 webdriverjs 后,我想试一试,看了https://github.com/camme/webdriverjs 中的readme.md,于是我开始了一个琐碎的测试。

var webdriverjs = require("webdriverjs"),
    client = webdriverjs.remote(), 
    expect = require("chai").expect;

suite('Functional tests', function(done) {
    setup(function(done) {
            client.init().url('http://www.google.com', done);
    });
    test('test if you can open a firefox page', function() {
            var inputType = client.getAttribute('#searchtext_home', 'type');
            expect(inputType).to.be.a('string');
            console.log(myString);
    });
    teardown(function(done) {
            client.end(done);
            //done();
    });
});

获取google的输入元素,期望它的类型是文本。 我最终在inputType 变量中得到了一个对象。

AssertionError: 期望 { Object (sessionId, desiredCapabilities, ...) } 是一个字符串

【问题讨论】:

    标签: javascript webdriver webdriver-io


    【解决方案1】:

    它确实从client.getAttribute() 返回一个对象。所以你应该使用它的第三个参数,它是一个这样的回调函数:

    test('test if you can open a firefox page', function(done) {
        client.getAttribute('#searchtext_home', 'type', function(err, inputType) {
            expect(inputType).to.be.a('string');
            done();
        });
    });
    

    查看更多详细示例代码here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多