通过 Grunt 将 Protractor 与 Yeoman 集成 [英] Integrating Protractor with Yeoman via Grunt

查看:22
本文介绍了通过 Grunt 将 Protractor 与 Yeoman 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Protractor 与 Yeoman 生产的脚手架集成.我遵循了一个教程,其中较旧的 scenario-runner 用于设置 e2e 测试(通过 grunt).

I want to integrate Protractor with a scaffold produced by Yeoman. I followed a tutorial and therein, the older scenario-runner was used for setting up e2e testing (via grunt).

我想升级我的脚手架并改用量角器.
有什么想法吗?

I would like to upgrade my scaffold and use Protractor instead.
Any thoughts?

推荐答案

  1. npm 安装 protractorgrunt-protractor-runner:

npm install protractor grunt-protractor-runner --save-dev

  • 为量角器创建一个配置文件 (protractor.conf.js),将 specsbaseUrl 更改为您的测试文件和测试服务器:

  • Create a config file for protractor (protractor.conf.js), change specs and baseUrl to your test files and test server:

    exports.config = {
      seleniumAddress: 'http://localhost:4444/wd/hub',
      specs: ['test/e2e/*_test.js'],
      baseUrl: 'http://localhost:9001' //default test port with Yeoman
    }
    

  • 更新您的 Gruntfile.js,在 karma 任务后添加以下内容:

  • Update your Gruntfile.js, add the following after the karma task:

    protractor: {
      options: {
        keepAlive: true,
        configFile: "protractor.conf.js"
      },
      run: {}
    }
    

  • 添加待测量角器任务

  • Add the protractor task under test

    grunt.registerTask('test', [
      'clean:server',
      'concurrent:test',
      'autoprefixer',
      'connect:test',
      'karma',
      'protractor:run'
    ]);
    

  • 下载并启动 selenium 服务器:

  • Download and start the selenium server:

    node_modules/protractor/bin/webdriver-manager update
    node_modules/protractor/bin/webdriver-manager start
    

    (在 Windows 中:)

    (In Windows:)

    node node_modules/protractor/bin/webdriver-manager update
    node node_modules/protractor/bin/webdriver-manager start
    

  • 更新您的 package.json,在 "devDependencies" 之后添加以下内容.这将在 npm install 之后运行命令,所以你不需要每次都记住.

  • Update your package.json, add the following after "devDependencies". This will run the command after npm install so you don't need to remember every time.

    "scripts": {
      "install": "node node_modules/protractor/bin/webdriver-manager update"
    }
    

  • 使用 grunt 运行测试

  • Run the test using grunt

    grunt test
    

  • 如果您希望量角器为您启动服务器,请删除

    If you want protractor to start the server for you, remove

    seleniumAddress: 'http://localhost:4444/wd/hub',
    

    来自protractor.conf.js,然后运行grunt test将在测试期间启动一个独立的selenium实例,并在运行测试套件后退出.

    from protractor.conf.js, then running grunt test will start a standalone selenium instance during the test and quit it after running the test suite.

    这篇关于通过 Grunt 将 Protractor 与 Yeoman 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆