質問

After discovering Mocha and webdriverjs, I wanted to give it a shot, after reading the readme.md in https://github.com/camme/webdriverjs, so i began with a trivial test.

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();
    });
});

Get the input element of google and expect its type is text. I end up with an object in inputType variable.

AssertionError: expected { Object (sessionId, desiredCapabilities, ...) } to be a string

役に立ちましたか?

解決

It does return an object from client.getAttribute(). So you should use it's 3rd parameter which is a callback function like this:

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();
    });
});

See more detail example code here.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top