Webdriver.io 因 NoSessionIdError 而崩溃

Webdriver.io crashes with NoSessionIdError

我正在尝试让 webdriver.io 和 Jasmine 工作。

their example 之后,我的脚本位于 test/specs/first/test2.js(根据配置)并包含:

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

我正在使用 wdio 作为测试 运行ner,并使用交互式设置对其进行设置。该配置是自动生成的,非常简单,所以我认为没有必要 post 它。

在另一个终端 window,我 运行ning selenium-server-andalone-2.47.1.jar 和 Java 7. 我确实在我的电脑上安装了 Firefox电脑(测试运行的时候就白启动了),我的电脑是运行ning OS 10.10.5.

这是我开始测试时发生的事情 运行ner:

$ 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)


$

我觉得这很奇怪和莫名其妙,特别是考虑到它甚至打印会话 ID。

有什么想法吗?

请查看 the docs 的 wdio 测试 运行ner。您不需要自己使用 init 创建实例。 wdio 测试 运行ner 负责为您创建和结束会话。

您的示例涵盖了独立的 WebdriverIO 用法(没有测试运行ner)。您可以找到使用 wdio here.

的示例

澄清一下:有两种使用 WebdriverIO 的方法。您可以自己将它嵌入到您的测试系统中(将其作为独立使用/或作为 scraper )。然后你需要处理诸如创建和结束实例或 运行 并行的事情。使用 WebdriverIO 的另一种方法是使用其测试 运行ner 称为 wdio。 test运行ner 获取一个配置文件,其中包含有关您的测试设置的大量信息,并生成实例更新 Sauce Labs 上的作业信息等等。

每个 Webdriver 命令都是异步执行的。 您在 afterEachtest it 测试中正确调用了 done 回调,但忘记在 beforeEach:

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