-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic setup to use global protractor and run tests
- Loading branch information
Carl Banbury
committed
Apr 11, 2015
0 parents
commit 4ca4426
Showing
15 changed files
with
385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* grunt-simple-protractor | ||
* | ||
* | ||
* Copyright (c) 2015 Carl Banbury | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'tasks/*.js', | ||
'<%= nodeunit.tests %>' | ||
], | ||
options: { | ||
jshintrc: '.jshintrc' | ||
} | ||
}, | ||
|
||
// Before generating any new files, remove any previously-created files. | ||
clean: { | ||
tests: ['tmp'] | ||
}, | ||
|
||
// Configuration to be run (and then tested). | ||
simple_protractor: { | ||
default_options: { | ||
options: { | ||
}, | ||
files: { | ||
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123'] | ||
} | ||
}, | ||
custom_options: { | ||
options: { | ||
separator: ': ', | ||
punctuation: ' !!!' | ||
}, | ||
files: { | ||
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123'] | ||
} | ||
} | ||
}, | ||
|
||
// Unit tests. | ||
nodeunit: { | ||
tests: ['test/*_test.js'] | ||
} | ||
|
||
}); | ||
|
||
// Actually load this plugin's task(s). | ||
grunt.loadTasks('tasks'); | ||
|
||
// These plugins provide necessary tasks. | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
|
||
// Whenever the "test" task is run, first clean the "tmp" dir, then run this | ||
// plugin's task(s), then test the result. | ||
grunt.registerTask('test', ['clean', 'simple_protractor', 'nodeunit']); | ||
|
||
// By default, lint and run all tests. | ||
grunt.registerTask('default', ['jshint', 'test']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2015 Carl Banbury | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# grunt-simple-protractor | ||
|
||
> Start webdriver manager, start a local test server and run protractor | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.5` | ||
|
||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: | ||
|
||
```shell | ||
npm install grunt-simple-protractor --save-dev | ||
``` | ||
|
||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
|
||
```js | ||
grunt.loadNpmTasks('grunt-simple-protractor'); | ||
``` | ||
|
||
## The "simple_protractor" task | ||
|
||
### Overview | ||
In your project's Gruntfile, add a section named `simple_protractor` to the data object passed into `grunt.initConfig()`. | ||
|
||
```js | ||
grunt.initConfig({ | ||
simple_protractor: { | ||
options: { | ||
// Task-specific options go here. | ||
}, | ||
your_target: { | ||
// Target-specific file lists and/or options go here. | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
### Options | ||
|
||
#### options.separator | ||
Type: `String` | ||
Default value: `', '` | ||
|
||
A string value that is used to do something with whatever. | ||
|
||
#### options.punctuation | ||
Type: `String` | ||
Default value: `'.'` | ||
|
||
A string value that is used to do something else with whatever else. | ||
|
||
### Usage Examples | ||
|
||
#### Default Options | ||
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.` | ||
|
||
```js | ||
grunt.initConfig({ | ||
simple_protractor: { | ||
options: {}, | ||
files: { | ||
'dest/default_options': ['src/testing', 'src/123'], | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
#### Custom Options | ||
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!` | ||
|
||
```js | ||
grunt.initConfig({ | ||
simple_protractor: { | ||
options: { | ||
separator: ': ', | ||
punctuation: ' !!!', | ||
}, | ||
files: { | ||
'dest/default_options': ['src/testing', 'src/123'], | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
|
||
## Release History | ||
_(Nothing yet)_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
exports.config = { | ||
seleniumAddress: 'http://localhost:4444/wd/hub', | ||
specs: ['spec.js'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
grunt.loadTasks('../../tasks'); | ||
|
||
grunt.initConfig({ | ||
simple_protractor: { | ||
options: { | ||
configFile: 'conf.js' | ||
}, | ||
all: {} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['simple_protractor']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
describe('Protractor Demo App', function() { | ||
it('should have a title', function() { | ||
browser.get('http://juliemr.github.io/protractor-demo/'); | ||
|
||
expect(browser.getTitle()).toEqual('Super Calculator'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "grunt-simple-protractor", | ||
"description": "Start webdriver manager, start a local test server and run protractor", | ||
"version": "0.0.1", | ||
"homepage": "", | ||
"author": { | ||
"name": "Carl Banbury", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "null" | ||
}, | ||
"bugs": { | ||
"url": "" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.5", | ||
"grunt-contrib-clean": "^0.5.0", | ||
"grunt-contrib-jshint": "^0.9.2", | ||
"grunt-contrib-nodeunit": "^0.3.3" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.5" | ||
}, | ||
"keywords": [ | ||
"gruntplugin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* grunt-simple-protractor | ||
* | ||
* | ||
* Copyright (c) 2015 Carl Banbury | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
var spawn = require('child_process').spawn; | ||
var spawnSync = require('child_process').spawnSync; | ||
|
||
module.exports = function(grunt) { | ||
grunt.registerMultiTask('simple_protractor', 'Start selenium webdriver, local server and run protractor tests', function() { | ||
var done = this.async(); | ||
var options = this.options({}); | ||
|
||
var webdriverBin = options.webdriver_bin || 'webdriver-manager'; | ||
var protractorBin = options.protractor_bin || 'protractor'; | ||
var configFile = options.config_file || 'conf.js'; | ||
|
||
var update = spawnSync(webdriverBin, ['update'], {stdio: 'pipe'}); | ||
var webdriver = spawn(webdriverBin, ['start']); | ||
var protractor; | ||
var pid; | ||
|
||
webdriver.stderr.on('data', function(data) { | ||
if (data.toString().search('WARN') > -1) { | ||
return grunt.fail.warn(data.toString()); | ||
} | ||
|
||
if (data.toString().search('ERROR') > -1) { | ||
return grunt.fail.warn(data.toString()); | ||
} | ||
|
||
// run protactor once the webdriver is running | ||
if (data.toString().search('INFO - Started SocketListener') > -1) { | ||
protractor = spawn(protractorBin, [configFile], {stdio: 'inherit'}); | ||
|
||
protractor.on('close', function(code) { | ||
process.kill(webdriver.pid); | ||
process.kill(pid); | ||
|
||
if (code !== 0) { | ||
return grunt.fail.warn(data.toString()); | ||
} | ||
|
||
return done(code); | ||
}); | ||
} | ||
}); | ||
|
||
webdriver.stdout.on('data', function(data) { | ||
|
||
// grab the pid from log so we can cleanly exit | ||
if (data.toString().search('seleniumProcess.pid') > -1) { | ||
pid = +data.toString().split(': ').pop(); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Testing: 1 2 3 !!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Testing, 1 2 3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 2 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Testing |
Oops, something went wrong.