UNPKG

4.31 kBMarkdownView Raw
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
7First, install `gulp-protractor` as a development dependency:
8
9```shell
10npm install --save-dev gulp-protractor
11```
12
13Then, add it to your `gulpfile.js`:
14
15```javascript
16var protractor = require("gulp-protractor").protractor;
17
18gulp.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
27You 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
29You can also ensure that the driver is installed by using the `webdriver_update` task. Have a look at the example folder.
30
31You have 2 options to start the selenium server.
32
33The first one is to let Protractor handle it automatically, including stopping it once your tests are done.
34To 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
42The second option is to let the gulp task handle it with the built-in webdriver snippet.
43If you decide to start it that way, the task will keep running indefinitely.
44
45```javascript
46var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
47gulp.task('webdriver_standalone', webdriver_standalone);
48```
49
50## API
51
52### protractor(options)
53
54#### options.configFile
55Type: `String`
56Default: `null`
57
58The path to your protractor config
59
60#### options.args
61Type: `Array`
62Default: `[]`
63
64Arguments 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
67Type: `Boolean`
68Default: `false`
69
70Enables 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
74If you want to avoid using a plugin at all, here are gulp tasks which install the webdriver and start protractor:
75
76First install the protractor package:
77```npm install --save-dev protractor```
78
79Then add these tasks to your ```gulpfile.js```:
80```javascript
81var gulp = require('gulp');
82var path = require('path');
83var child_process = require('child_process');
84
85function 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
92gulp.task('protractor-install', function(done){
93 child_process.spawn(getProtractorBinary('webdriver-manager'), ['update'], {
94 stdio: 'inherit'
95 }).once('close', done);
96});
97
98gulp.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
107You 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