webdriverjs:预期的字符串有一个对象

时间:2013-12-23 13:26:42

标签: javascript webdriver webdriver-io

在发现了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();
    });
});

获取谷歌的输入元素,并期望其类型为文本。 我最终在inputType变量中找到了一个对象。

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

1 个答案:

答案 0 :(得分: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

的更多详细信息