【问题标题】:Getting Selenium Going for Use with Protractor for my AngularJS app让 Selenium 与 Protractor 一起用于我的 AngularJS 应用程序
【发布时间】:2014-05-13 14:59:49
【问题描述】:

我正在 Windows 上构建一个 AngularJS 应用程序。我想用 Jasmine 创建端到端测试。据我了解,我需要量角器来运行这些类型的测试。出于这个原因,我在 package.json 中添加了以下内容:

"devDependencies": {
  ...
  "grunt-protractor-runner": "0.2.4",
  "selenium-webdriver":"2.41.0",
  ...
}

在我的 gruntfile.js 中,我已经这样配置 Protractor:

grunt.initConfig({
  protractor: {
    options: {
      configFile: "node_modules/protractor/referenceConf.js", // Default config file
      keepAlive: true, // If false, the grunt process stops when the test fails.
      noColor: false, // If true, protractor will not use colors in its output.
      args: {
        // Arguments passed to the command
      }
    },
    tests: {
      options: {
        configFile: "tests/config/e2e.conf.js",
        args: {} // Target-specific arguments
      }
    },
  }
});

然后我运行protractor:tests 目标。 e2e.conf.js 的内容如下所示:

exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://localhost:4444/wd/hub',

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to the location of the spec file. They may
    // include glob patterns.
    specs: ['../../tests/e2e/user-tests.e2e.js'],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true, // Use colors in the command line report.
    }
};

现在,当我从命令行运行 grunt 时,我收到一条错误消息:

Using the selenium server at http://localhost:4444/wd/hub

C:\Projects\MyProject\node_modules\grunt-protractor-runner\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702
      throw error;
            ^
Error: ECONNREFUSED connect ECONNREFUSED
...

我不明白为什么会出现此错误。我在Protractor Getting Started Guide 中看到它期望一个 selenium 独立服务器正在运行。但是,我认为这就是 Grunt 任务运行器的目的:启动 selenium 服务器。我在 node_modules\grunt-protractor-runner\node_modules\protractor\bin 中看到 webdriver-manager,但是,如果我切换到该目录并从命令行运行 webdriver-manager update,我会收到一条错误消息:

'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.

如何让 selenium 部分运行,以便我可以使用量角器运行端到端测试?

谢谢!

【问题讨论】:

    标签: angularjs selenium selenium-webdriver protractor


    【解决方案1】:

    你试过“节点”命令吗?

    它对我有用:

    node .\node_modules\grunt-protractor-runner\node_modules\protractor\bin\webdriver-manager update
    

    这应该为您下载 chromedriver 和 selenium 服务器。如果没有,你也可以手动下载/解压:

    在:

    • src/test/config/selenium/selenium-server-standalone.jar
    • src/test/config/selenium/chromedriver.exe

    另一件事是您需要确保 Chrome 已安装:

    <WINDOWS_USERS_FOLDER>\<USERNAME>\AppData\Local\Google\Chrome\Application\chrome.exe
    

    【讨论】:

      【解决方案2】:

      首先:

      • 里面有很多我不明白的组件:)
      • 随时添加 cmets 以帮助我改进答案。
      • 我确实知道一些硒,所以这里是。
      seleniumAddress: 'http://localhost:4444/wd/hub',
      

      对我来说,这一行表明您正在尝试运行Selenium Grid Server.

      以下是如何启动它:(是的,据我所知需要手动启动) 从单独的控制台运行以下命令:

      java -jar selenium-server-standalone-2.41.0.jar -role hub
      #now wait a few seconds for the hub to start
      java -jar selenium-server-standalone-2.41.0.jar -role node  -hub http://localhost:4444/grid/register
      

      我们刚刚做了什么?

      • 启动了一个集线器。这个中心就像一个测试分发器 - 它接收请求。
      • 启动了一个节点。 (您可以启动任意数量的节点)。该节点将实际进行测试。

      您可以验证此服务器是否已成功启动。只需访问浏览器上的本地主机链接即可。

      陷阱:

      • 检查您的防火墙是否没有给您带来问题。我在开始使用 Windows 7 时遇到了严重的问题,最终转移到了 Ubuntu(但这可能只是我的情况)。
      • 为 Windows 防火墙上的传入和传出连接打开端口 4444(用于集线器)、5555(用于节点)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        • 2011-04-08
        • 1970-01-01
        • 1970-01-01
        • 2016-12-13
        • 2013-12-03
        相关资源
        最近更新 更多