Protractor & Jasmine Configuration on Jenkins - node.js

I am trying to configure Protractor on Jenkins for CTI.... I have already setup Protractor along with Jasmine and trying to get it integrated with Jenkins.
I have gone through several links & blogs on internet but none seem to be helpful in providing detailed information on how to get the Protractor configured with Jenkins.
Any help or pointing towards the right blog or video will be really appreciated. Thanks

#Vishal
Please find the below snippet you can add as grunt task.
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
exec: {
protractorRunAppsTest: {
cmd: 'C:\\Program Files\\nodejs\\node.exe C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\protractor\\built\\cli.js C:\\Jenkins\\workspace\\test\\conf.js'
}
},
server: {
port:3000,
base: ['app']
},
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('server', 'Start node server', function() {
grunt.log.writeln('Started server on port 3000');
require('./app.js');
});
grunt.registerTask('runAppsTest', ['exec:protractorRunAppsTest']);
};
Save the above code as Gruntfile.js
Make sure this is in the workspace folder for jenkins.
In Jenkins job add the 'Build' Section (i am assuming Jenkins is windows server)
add "Execute Windows Batch Command" and add the below content to the text field there.
cd %WORKSPACE%
grunt server runAppsData || exit 0
I hope this would work for you. Please try and let me know.
Consider rating my answer.

#Vishal try to use grunt for doing the same. So that you can easily integrate the Jenkins job with grunt task details.
Just configure and register task with grunt.
Then use the grunt task to run in jenkins.
If you want i can provide more details.

Related

How to get wdio running through IntelliJ run/debug configurations?

I can run the tests from the command line using
> ./node_modules/.bin/wdio wdio.conf.js
But if I try to run this from IntelliJ's run/debug configuration I get various different errors.
Featurefile or directory: /path_to_my_feature_file/myfeature.feature
Cucumber.js arguments: wdio.conf.js
Executable path: /path_to_my_project/node_modules/.bin/wdio
gives me
more than one config file specified
If I remove the Cucumber Arguments, it just runs indefinitely. If I stop it running I get the error
Failed loading configuration file
It looks like there's some kind of issue with loading the config file, but I don't know how to fix it. Any suggestions? wdio.conf.js exists and is in the project root.
WebStorm doesn't provide any special support for wdio test runner. But you can still run/debug the tests using Node.js run configuration like the following:
But this doesn't work out of the box due to problems related to using non-tty environment (Node.js run console in IDEA is non-tty). As a workaround, please try commenting out if (process.stdin.isTTY) and else branch in node_modules\webdriverio\build\lib\cli.js:
//if (process.stdin.isTTY) {
launch();
/*
} else {
var stdinData = '';
/!*
* get a list of spec files to run from stdin, overriding any other
* configuration suite or specs.
*!/
var stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function (data) {
stdinData += data;
});
stdin.on('end', function () {
if (stdinData.length > 0) {
args['specs'] = stdinData.trim().split(/\r?\n/);
}
launch();
});
}*/
see WEB-31745
To get this to work with webdriverio v5 and higher you need to set in the debug configurations screen above
the path to the runner as the javascript file to execute:
node_modules#wdio\cli\bin\wdio.js
and the conf file as the application parameters:
wdio.conf.js

How to debug app startup with Gulp

I have run into a road block with a new team I am working with that supports a node app. The app is launched via Gulp, and the setup is such that there is a "core" NPM module that defines a bunch of gulp tasks and a "server", and our app simply installs this package and our code is copied in as a "plugin" to the server.
In our gulpfile.js, we have something like:
var gulp = require('gulp');
var workflow = require('base-workflow');
workflow.use({ gulp: gulp });
gulp.task('default'), ['base:default']);
...more stuff
Where base:default is pulled in and a couple of Hapi servers are ultimately started (one as a "web" app, one as the "rest" proxy app to a real Java-based REST services). What I would like to do is setup node-inpector so that I can troubleshoot the startup of the app because I have found that the latest versions of their base packages are not Mac-compatible.
What I have tried is to install gulp-node-inspector with the following changes:
var gulp = require('gulp');
var nodeInspector = require('gulp-node-inspector');
var workflow = require('base-workflow');
workflow.use({ gulp: gulp });
gulp.task('default'), ['base:default']);
gulp.task('debug', ['default'], function() { gulp.src([]).pipe(nodeInspector({debugBrk: true})); });
...more stuff
and also:
var gulp = require('gulp');
var nodeInspector = require('gulp-node-inspector');
var workflow = require('base-workflow');
workflow.use({ gulp: gulp });
gulp.task('default'), ['base:default']);
gulp.task('debug', function() { gulp.src(['default']).pipe(nodeInspector({debugBrk: true})); });
...more stuff
but neither of those works. Part of this is most likely my lack of understanding of Gulp. Does anyone know how I can debug this app?
I spent a fair bit of time googling and trying the various solutions out there; in the end the one that worked for me was the accepted answer found on this page:
How to debug gulpfile.js
This was the only one that allowed me to actually hit my "debugger" command in my gulp task.
I should also note that I had to completely uninstall and reinstall "node-inspector"; there was a version problem and when I was on the verge of solving it I was getting some "cannot find module" error because the version of node-inspector was causing it to point to the wrong folder. Once I uninstalled and reinstalled (via npm) then it worked. In my case I'm on a Windows machine and the command that worked looked like the following:
node-debug C:\myPathWhereGulpfileDotJsExists\node_modules\gulp\bin\gulp.js --gulpfile C:\myPathWhereGulpfileDotJsExists\gulpfile.js myTestTaskContainingDebuggerCommand
Maby this solution help you
node --inspect --debug-brk ./node_modules/gulp fonts
The best way to do this now is to add a debugger; to the place in the file you would like to add a breakpoint to, or set it manually once the debugger has started with setBreakpoint('gulpFile.js', 1)
Then simply
node inspect --inspect-brk $(which gulp) taskName
c
More information about debugging with node here

Running grunt task with api, without command line

I want to create and run grunt task in node.js code for test use.
var foo = function() {
var grunt = require("grunt");
var options = {"blahblah": null} // ...creating dynamic grunt options, such as concat and jshint
grunt.initConfig(options);
grunt.registerTask('default', [/*grunt subtasks*/]);
}
But this doesn't work. Grunt doesn't seem to run any task. I'm almost sure that there is some API to run grunt task externally without command line, but don't know how to do it.
Is there any way to do it?
You can. I don't know why anyone would need to do this as currently Grunt is a command line tool. WARNING: I don't recommend running Grunt in this way. But here it is:
var grunt = require('grunt');
// hack to avoid loading a Gruntfile
// You can skip this and just use a Gruntfile instead
grunt.task.init = function() {};
// Init config
grunt.initConfig({
jshint: {
all: ['index.js']
}
});
// Register your own tasks
grunt.registerTask('mytask', function() {
grunt.log.write('Ran my task.');
});
// Load tasks from npm
grunt.loadNpmTasks('grunt-contrib-jshint');
// Finally run the tasks, with options and a callback when we're done
grunt.tasks(['mytask', 'jshint'], {}, function() {
grunt.log.ok('Done running tasks.');
});
You can get inspiration on how to run grunt from code by looking at grunt-cli which does this and which is a project maintained by the grunt folks.
Grunt is launched from code in grunt-cli/bin/grunt and you can read more about the options in grunt/lib/grunt/cli.js.
I use it in a private project like this:
var grunt = require("grunt");
grunt.cli({
gruntfile: __dirname + "/path/to/someGruntfile.js",
extra: {key: "value"}
});
The key "extra" will be available from inside the gruntfile as grunt.option("extra")
Here is a bloggpost that describes an alternative way to run a grunt task: http://andrewduthie.com/2014/01/14/running-grunt-tasks-without-grunt-cli/

How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project?

This is a bit of an oddball question.
Capistrano 2.14.2
I'm using capistrano to deploy a couple of Node.js projects, and this works fine (from within the same rvm and gemset Ruby installation). However, I'd like to have Airbrake be notified of these deployments.
Using the 'airbrake' Node.js module, and calling
airbrake.trackDeployment({repo: '...'});
works, but not sure how to reliably call this just once at deploy time. If I call it within my server, then Airbrake is notified of a "deployment" every time my server starts, which is obviously not correct.
Adding
require 'airbrake/capistrano'
to deploy.rb definitely does not work.
How do others successfully use
airbrake.trackDeployment
?
You could create a simple js file you'd run locally (on your machine for example) that notifies airbrake as a last deploy task. You could for example use the backtick operator to run a task:
deploy.task :notify_airbrake do
`node notify_airbrake.js`
end
If you don't have node installed locally, you could also pick one of the servers to run the notification script through ssh:
deploy.task :notify_airbrake do
`ssh youserver "node notify_airbrake.js"`
end
Based on this solution http://dwradcliffe.com/2011/09/26/using-airbrake-with-node.html (which is clearly embedded in a Rails app.), I came up with the following, which depends solely on Javascript:
In my Node.js root directory, create a deploy.js file, like so:
var airbrake = require('airbrake').createClient("AIRBRAKE_API_KEY");
var deployment = {rev: process.argv[2],
repo: process.argv[3],
env: process.argv[4],
user: process.argv[5]};
airbrake.trackDeployment(deployment, function(err, params) {
if (err) {throw err}
console.log('Tracked deployment of %s to %s', params.rev, params.env);
})
In config/deploy.rb, add
require 'airbrake/capistrano'
and
namespace :airbrake do
desc "Notify Airbrake of a new deploy."
task :deploy do
system "node deploy.js #{current_revision} #{repository} #{stage} #{user}"
end
end

What's the purpose of gruntjs server task?

I'm learning how to propel use gruntjs. I found the server task but I can't get the point.
Can i use the server task mapping concatenated/minified files to test my application (uses backbone.js) without moving or placing source files in web server root? Without apache for example.
If no, what's the supposed use of server task?
The server task is used to start a static server with the base path set as the web root.
Example: Serve ./web-root as http://localhost:8080/:
grunt.initConfig({
server: {
port: 8080,
base: './web-root'
}
});
It will function similar to an Apache server, serving up static files based on their path, but uses the http module via connect to set it up (source).
If you need it to serve more than just static files, then you'll want to consider defining a custom server task:
grunt.registerTask('server', 'Start a custom web server.', function() {
grunt.log.writeln('Starting web server on port 1234.');
require('./server.js').listen(1234);
});
And custom server instance:
// server.js
var http = require('http');
module.exports = http.createServer(function (req, res) {
// ...
});
Can I use the server task mapping concatenated/minified files to test my application [...]
Concatenation and minification have their own dedicated tasks -- concat and min -- but could be used along with a server task to accomplish all 3.
Edit
If you want it to persist the server for a while (as well as grunt), you could define the task as asynchronous (with the server's 'close' event):
grunt.registerTask('server', 'Start a custom web server.', function() {
var done = this.async();
grunt.log.writeln('Starting web server on port 1234.');
require('./server.js').listen(1234).on('close', done);
});
The server task is now the connect task and it's included in the grunt-contrib-connect package.
The connect task starts a connect web server.
Install this plugin with this command:
npm install grunt-contrib-connect --save-dev
Note: --save-dev includes the package in your devDependencies, see https://npmjs.org/doc/install.html
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-contrib-connect');
Run this task with the grunt connect command.
Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option, and can be enabled ad-hoc by running the task like grunt connect:targetname:keepalive. targetname is equal to "server" in the code sample below.
In this example, grunt connect (or more verbosely, grunt connect:server) will start a static web server at http://localhost:9001/, with its base path set to the www-root directory relative to the Gruntfile, and any tasks run afterwards will be able to access it.
// Project configuration.
grunt.initConfig({
connect: {
server: {
options: {
port: 9001,
base: 'www-root'
}
}
}
});
The point of the server task is to have quick and dirty access to static files for testing. grunt server IS NOT a production server environment. It really should only be used during the grunt lifecycle to get static testing assets to the testing environment. Use a full-fledged server, possibly controlled by the NPM lifecycle scripts, for production environments.

Resources