javascript - Webdriver.io 因 NoSessionIdError 崩溃

标签 javascript selenium webdriver-io

我正在尝试让 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 作为测试运行器,并使用交互式设置对其进行设置。该配置是自动生成的并且非常简单,所以我认为没有必要发布它。

在另一个终端窗口中,我正在使用 Java 7 运行 selenium-server-andalone-2.47.1.jar。我的电脑上安装了 Firefox(测试运行时它空白启动),并且我的电脑正在运行操作系统 10.10.5。

这是我启动测试运行程序时发生的情况:

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


$

我觉得这很奇怪而且莫名其妙,尤其是考虑到它甚至会打印 session ID。

有什么想法吗?

最佳答案

请查看the docs在 wdio 测试运行器上。您不需要自己使用 init 创建实例。 wdio 测试运行器负责为您创建和结束 session 。

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

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

关于javascript - Webdriver.io 因 NoSessionIdError 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32533690/

相关文章:

javascript - 如何获取 knockout 同级数据绑定(bind)属性

RSelenium findElement 适用于 firefox :2. 53.1 但不适用于 firefox:latest

javascript - 如何从数据表中删除 'records per page' 标签文本

javascript - 在 jquery 中隐藏一些 future 的元素

ruby-on-rails - Rails 3 中的 Cucumber、Webrat 和 Selenium NoMethodError

python - 我如何使用 Python 和 Selenium 遍历 webelements 列表?

selenium - 确认 WebdriverIO 中的 Chrome 导航对话框

javascript - 如何使用 Webdriver.io 测试过快的 AJAX 响应?

javascript - WebdriverIO-Jasmine 异步功能未在 10000 毫秒内完成

javascript - ng-messages-include 不起作用