1 | # gulp-protractor [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
|
2 |
|
3 | > Run your [angular protractor](https://github.com/angular/protractor) tests with [gulp](https://github.com/wearefractal/gulp)
|
4 |
|
5 | ## Usage
|
6 |
|
7 | First, install `gulp-protractor` as a development dependency:
|
8 |
|
9 | ```shell
|
10 | npm install --save-dev gulp-protractor
|
11 | ```
|
12 |
|
13 | Then, add it to your `gulpfile.js`:
|
14 |
|
15 | ```javascript
|
16 | var protractor = require("gulp-protractor").protractor;
|
17 |
|
18 | gulp.src(["./src/tests/*.js"])
|
19 | .pipe(protractor({
|
20 | configFile: "test/protractor.config.js",
|
21 | args: ['--baseUrl', 'http://127.0.0.1:8000']
|
22 | }))
|
23 | .on('error', function(e) { throw e })
|
24 | ```
|
25 |
|
26 | ### Protractor Webdriver
|
27 | You have to update and start a standalone selenium server. [Please read the offical instructions](https://github.com/angular/protractor#appendix-a-setting-up-a-standalone-selenium-server).
|
28 |
|
29 | You can also ensure that the driver is installed by using the `webdriver_update` task. Have a look at the example folder.
|
30 |
|
31 | You have 2 options to start the selenium server.
|
32 |
|
33 | The first one is to let Protractor handle it automatically, including stopping it once your tests are done.
|
34 | To do that, simply point to the selenium jar in the protractor config file (you will need to update the version number accordingly) instead of the address:
|
35 |
|
36 | ```javascript
|
37 | // The file path to the selenium server jar ()
|
38 | seleniumServerJar: './node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.2.0.jar',
|
39 | // seleniumAddress: 'http://localhost:4444/wd/hub',
|
40 | ```
|
41 |
|
42 | The second option is to let the gulp task handle it with the built-in webdriver snippet.
|
43 | If you decide to start it that way, the task will keep running indefinitely.
|
44 |
|
45 | ```javascript
|
46 | var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
|
47 | gulp.task('webdriver_standalone', webdriver_standalone);
|
48 | ```
|
49 |
|
50 | ## API
|
51 |
|
52 | ### protractor(options)
|
53 |
|
54 | #### options.configFile
|
55 | Type: `String`
|
56 | Default: `null`
|
57 |
|
58 | The path to your protractor config
|
59 |
|
60 | #### options.args
|
61 | Type: `Array`
|
62 | Default: `[]`
|
63 |
|
64 | Arguments get passed directly to the protractor call [Read the docs for more information](https://github.com/angular/protractor/blob/master/docs/getting-started.md#setup-and-config)
|
65 |
|
66 | #### options.debug
|
67 | Type: `Boolean`
|
68 | Default: `false`
|
69 |
|
70 | Enables Protractor's [debug mode](https://github.com/angular/protractor/blob/master/docs/debugging.md), which can be used to pause tests during execution and to view stack traces.
|
71 |
|
72 |
|
73 | # Running Protractor without a plugin
|
74 | If you want to avoid using a plugin at all, here are gulp tasks which install the webdriver and start protractor:
|
75 |
|
76 | First install the protractor package:
|
77 | ```npm install --save-dev protractor```
|
78 |
|
79 | Then add these tasks to your ```gulpfile.js```:
|
80 | ```javascript
|
81 | var gulp = require('gulp');
|
82 | var path = require('path');
|
83 | var child_process = require('child_process');
|
84 |
|
85 | function getProtractorBinary(binaryName){
|
86 | var winExt = /^win/.test(process.platform)? '.cmd' : '';
|
87 | var pkgPath = require.resolve('protractor');
|
88 | var protractorDir = path.resolve(path.join(path.dirname(pkgPath), '..', 'bin'));
|
89 | return path.join(protractorDir, '/'+binaryName+winExt);
|
90 | }
|
91 |
|
92 | gulp.task('protractor-install', function(done){
|
93 | child_process.spawn(getProtractorBinary('webdriver-manager'), ['update'], {
|
94 | stdio: 'inherit'
|
95 | }).once('close', done);
|
96 | });
|
97 |
|
98 | gulp.task('protractor-run', function (done) {
|
99 | var argv = process.argv.slice(3); // forward args to protractor
|
100 | child_process.spawn(getProtractorBinary('protractor'), argv, {
|
101 | stdio: 'inherit'
|
102 | }).once('close', done);
|
103 | });
|
104 |
|
105 | ```
|
106 |
|
107 | You can add command line arguments for protractor behind the gulp task:
|
108 |
|
109 | ```gulp protractor-run --specs=runOnlyThisFile.js```
|
110 |
|
111 |
|
112 | ## License
|
113 |
|
114 | [MIT License](http://en.wikipedia.org/wiki/MIT_License)
|
115 |
|
116 | [npm-url]: https://npmjs.org/package/gulp-protractor
|
117 | [npm-image]: https://badge.fury.io/js/gulp-protractor.png
|
118 |
|
119 | [travis-url]: http://travis-ci.org/mllrsohn/gulp-protractor
|
120 | [travis-image]: https://secure.travis-ci.org/mllrsohn/gulp-protractor.png?branch=master
|
121 |
|
122 | [depstat-url]: https://david-dm.org/mllrsohn/gulp-protractor
|
123 | [depstat-image]: https://david-dm.org/mllrsohn/gulp-protractor.png
|
124 |
|
\ | No newline at end of file |