Integrating Protractor with Yeoman via Grunt

后端 未结 3 1639
有刺的猬
有刺的猬 2020-12-04 12:11

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 test

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 13:07

    1. Install protractor and grunt-protractor-runner from npm:

      npm install protractor grunt-protractor-runner --save-dev
      
    2. 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
      }
      
    3. Update your Gruntfile.js, add the following after the karma task:

      protractor: {
        options: {
          keepAlive: true,
          configFile: "protractor.conf.js"
        },
        run: {}
      }
      
    4. Add the protractor task under test

      grunt.registerTask('test', [
        'clean:server',
        'concurrent:test',
        'autoprefixer',
        'connect:test',
        'karma',
        'protractor:run'
      ]);
      
    5. Download and start the selenium server:

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

      (In Windows:)

      node node_modules/protractor/bin/webdriver-manager update
      node node_modules/protractor/bin/webdriver-manager start
      
    6. 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"
      }
      
    7. Run the test using grunt

      grunt test
      

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

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

    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.

提交回复
热议问题