Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

angularjs - Integrating Protractor with Yeoman via 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...