Webdriver.io crashes with NoSessionIdError

早过忘川 提交于 2020-01-15 10:50:36

问题


I'm trying to get webdriver.io and Jasmine working.

Following their example, my script is at test/specs/first/test2.js (in accordance with the configuration) and contains:

var webdriverio = require('webdriverio');


describe('my webdriverio tests', function() {

    var client = {};
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;

    beforeEach(function() {
        client = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
        client.init();
    });

    it('test it', function(done) {
        client
            .url("http://localhost:3000/")
            .waitForVisible("h2.btn.btn-primary")
            .click("h2.btn.btn-primary")
            .waitForVisible("h2.btn.btn-primary")
            .call(done);
    });

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

I'm using wdio as the test runner, and set it up using the interactive setup. That config is automatically-generated and all pretty straightforward, so I don't see a need to post it.

In another terminal window, I am running selenium-server-andalone-2.47.1.jar with Java 7. I do have Firefox installed on my computer (it blankly starts when the test is run), and my computer is running OS 10.10.5.

This is what happens when I start the test runner:

$ wdio wdio.conf.js 


=======================================================================================
Selenium 2.0/webdriver protocol bindings implementation with helper commands in nodejs.
For a complete list of commands, visit http://webdriver.io/docs.html. 
=======================================================================================

[18:17:22]:  SET SESSION ID 46731149-79aa-412e-b9b5-3d32e75dbc8d
[18:17:22]:  RESULT      {"platform":"MAC","javascriptEnabled":true,"acceptSslCerts":true,"browserName":"firefox","rotatable":false,"locationContextEnabled":true,"webdriver.remote.sessionid":"46731149-79aa-412e-b9b5-3d32e75dbc8d","version":"40.0.3","databaseEnabled":true,"cssSelectorsEnabled":true,"handlesAlerts":true,"webStorageEnabled":true,"nativeEvents":false,"applicationCacheEnabled":true,"takesScreenshot":true}
NoSessionIdError: A session id is required for this command but wasn't found in the response payload 
    at waitForVisible("h2.btn.btn-primary") - test2.js:21:14 

/usr/local/lib/node_modules/webdriverio/node_modules/q/q.js:141
                throw e;
                      ^
NoSessionIdError: A session id is required for this command but wasn't found in the response payload



0 passing (3.90s)


$

I find this very strange and inexplicable, especially considering that it even prints the session ID.

Any ideas?


回答1:


Please check out the docs on the wdio test runner. You don't need to create an instance using init on your own. The wdio test runner takes care on creating and ending the session for you.

Your example covers the standalone WebdriverIO usage (without testrunner). You can find examples which use wdio here.

To clarify that: there are two ways of using WebdriverIO. You can embed it in your test system by yourself (using it as standalone / or as a scrapper). Then you need to take care of things like create and end an instance or run those in parallel. The other way to use WebdriverIO is using its test runner called wdio. The testrunner takes a config file with a bunch of information on your test setup and spawns instances updates job information on Sauce Labs and so on.




回答2:


Every Webdriver command gets executed asynchronously. You properly called the done callback in afterEach and in your test it test, but forgot to do it in beforeEach:

beforeEach(function(done) {
    client = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
    client.init(done);
});


来源:https://stackoverflow.com/questions/45922525/error-a-session-id-is-required-for-this-command-but-wasnt-found-in-the-respons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!