【问题标题】:Getting ETIMEDOUT error when running protractor conf.js运行量角器 conf.js 时出现 ETIMEDOUT 错误
【发布时间】:2016-12-09 03:28:34
【问题描述】:

我是量角器的初学者。我做了运行量角器所需的安装。当尝试运行量角器文档中提到的示例脚本时,我收到 ETIMEDOUT 错误。并且 url 指向 127.0.0.1:4444。同样的 url 也不能手动访问。但是在尝试http://localhost:4444/wd/hub 时,页面会正常打开。我不确定为什么 conf.js 试图访问 127.0.0.1:4444,即使我将“seleniumAddress”参数提供给“http://localhost:4444/wd/hub”。请大家帮我解决这个问题

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js']
};

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);
  });
});

【问题讨论】:

  • localhost什么都不是,它表示ip地址127.0.0.1。在执行量角器测试之前,在新的终端窗口中输入以下命令sudo webdriver-manager update && webdriver-manager start,然后执行protractor conf.js

标签: selenium-webdriver protractor webdriver-manager


【解决方案1】:

我同意其他回答。 http://localhost:4444/wd/hubhttp://127.0.0.1:4444/wd/hub 相同。通常这是在您的 /etc/hosts 文件中定义的。

由于我认为您只是尝试运行 Protractor 测试,因此只要您使用 webdriver-manager update 下载了二进制文件,您就可以执行以下两个选项之一:

  1. 设置 directConnect: true(并删除 seleniumAddress。这适用于没有 selenium 独立服务器的 chrome 或 firefox(版本 47*)。
  2. 一起删除seleniumAddress。 Protractor 会在测试前为您启动 selenium 独立服务器,然后在测试结束时将其拆除。

注意:为使上述工作正常,webdriver-manager update 应从项目目录运行以将二进制文件下载到正确的目录。 node node_modules/.bin/webdriver-manager update./node_modules/.bin/webdriver-manager update 之类的东西应该将驱动程序二进制文件下载到 node_modules/protractor/node_modules/webdriver-manager/selenium

  • 那么为什么不支持当前较新版本的 Firefox 47。我们目前正在测试 Firefox 48+,但仍有一些未解决的问题。

【讨论】:

  • 感谢您,从 selenium 目录执行时效果很好。
【解决方案2】:

您需要 2 个终端。

  1. 在第一个终端中,运行以下命令: webdriver-manager 启动 这将创建一个供节点/客户端访问的服务器(您已在 seleniumAddress 中添加)

  2. 在第二个终端中,运行以下命令: 量角器 conf.js 这将使用在http://localhost:4444/wd/hub 创建的服务器启动您的脚本。

而 localhost 与 127.0.0.1 相同。

【讨论】:

    【解决方案3】:

    如果 localhost 与 127.0.0.1 不同,则听起来您的主机文件已被玩弄或更恶劣的网络问题。我认为我们没有足够的信息来正确调试您遇到此问题的原因,但我想建议一种解决方法。为什么不使用您实际的本地内部 IPv4 地址?

    在 Windows 中获取 IPv4 地址列表

    ipconfig | findstr /R /C:"IPv4 Address"
    

    在 Linux 类型中获取 IPv4 地址列表

    hostname -i
    

    在 Mac 上获取 IPv4 地址

    ifconfig |grep inet
    

    mac上的地址应该在inet和netmask之间的最后一行

    你的配置文件应该看起来像这样

    exports.config = {
      seleniumAddress: 'http://192.138.0.100:4444/wd/hub',
      specs: ['todo-spec.js']
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2016-05-27
      相关资源
      最近更新 更多