running protractor test using npm - jenkins

I am new to protractor, node and all. I have learned to create scripts with protractor. But now I need to run this test scripts along the build.
I have seen people can run it with npm test/ npm test e2e. How can I achieve this.
My project structure,
webapp/test/e2e
In my project they are using webpack and karma.
Sorry, I am really noob at this and don't know how to set it up.
We also need to configure it in Jenkins, so it runs and generates a flag for success or failure.
Any suggestions to set it up would really really be helpful. Please be as elaborate as possible as it is hard for me to understand things as of now.
Thank you so much!

If the package.json file is in the root folder of the project you can add the code below to it and run it using npm test and npm run test:e2e. This assumes you have Protractor and Karma installed locally in your project which would be a best practice (if it is not in the package.json as a dependency it probably is not).
"scripts": {
"postinstall": "node_modules/protractor/bin/webdriver-manager update",
"test": "node_modules/karma/bin/karma start webapp/test/unit/karma.conf.js"
"test:e2e": "node_modules/protractor/bin/protractor webapp/test/e2e/conf.js"
}
postinstall - This will run webdriver-manager update locally automatically after running npm install, you could run into issues with missing drivers when using a CI Server like Jenkins that is continuously checking our your repository (it also saves you a CI step)
test - This is equivalent to karma start karma.conf.js
test:e2e - This is equivalent to protractor conf.js it is just running it locally. To run these tests type npm run test:e2e from the directory with your package.json
It is recommended to not combine Protractor and Karma together (although possible) Karma should be used for Unit and Integration tests and Protractor should be used for e2e tests.
As an extra tip it is possible to pass protractor or karma command line arguments through the npm scripts. Simply append it the way you normally would (e.g.
"webapp/test/e2e/conf.js --baseUrl=https://yourbaseurl.com/")
Your question regarding integrating NPM into Jenkins has already been answered fairly well here how to run npm/grunt command from jenkins but be aware running your tests entirely in Jenkins will cause it to run headlessly which when using Windows will cause it to run in Session 0 where the screen resolution will be smaller which causes some tests to fail, opening the selenium server beforehand in a Terminal/Powershell window will cause Jenkins to route your tests through that so it will visually display on your computer.

Related

Error when trying to deploy signal-twilio-video-webrtc-go-demo

I'm trying to deploy a simple video chat as part of our website customer support. The sample code has been a big help and so far I have successfully built and deployed both of these:
twilio/twilio-video-app-react
twilio/twilio-video-diagnostics-react-app
The instructions for both of those were clear and I had no problem deploying them to the serverless service.
However, the react app has more features than we need, so I was hoping to try a smaller, simpler sample web application from here:
philnash/signal-twilio-video-webrtc-go-demo
My problem/question is that when I follow those instructions and get to:
npm run deploy
all I get is an error message:
signal-twilio-videe-webrtc-go#0.0.0 predeploy
build
sh: build: command not found
Can anyone explain what that means and how I can get past that error?
Twilio developer evangelist and creator of that demo here.
Apologies for getting the predeploy script wrong, I thought I knew what I was doing.
I have now updated the predeploy script to npm run build as you suggested in your comment.
As for why this was a problem, I believe that I was under the misconception that one npm script could refer to another without the npm run prefix. However, it cannot. So, to run one npm script from another, as in this predeploy script, I needed to refer to the script as npm run build. I am referring to another script like this because the predeploy script is automatically run by npm before the deploy script (you can do this with any script you create, and you can run scripts after using the post prefix too).
I have updated the repo with this, as well as some dependency updates, so hopefully this doesn't cause further problems.

How to deploy a angular project using Jenkins in windows

I'm trying to deploy an angular project using Jenkins. In the window bash, I used the command npm install and npm run ng -- build to install packages and to build the project. Later when I try to host using http-server it throws an error like 'http-server' is not recognized as an internal or external command, and it clearly shows it is not supporting any Angular-related commands in it. Suggest me anyway to solve this. Thanks in advance

npm library fails to install in GitLab CI

My Docker image build has been failing to build lately and I've managed to trace down
where exactly it struggles.
When the runner is executing RUN npm install react-scripts#2.1.8 -g --silent --no-optional (from Dockerfile)
it fails and gives no error output to work with. Job log shows no clue as to why it failed.
I figured I could SSH into the CI server but GitLab doesn't support direct SSH access into CI server for debugging purposes.
My question is how can I debug this ? What steps I should take ? I don't deal every day with
bug where I get no error output.
What are the conditions in which GitLab runner may fail to install it ?
Note:
I ran it locally and no problem whatsoever hence it must be problem within the CI.
is the build of your image is ok in your computer ? You can also install a gitlab runner in your computer to test your gitlabci file
Try removing the --silent flag from the npm install command. I reckon you'll see a bit more then.
Timeout of the build runner was to blame in this particular case. As soon as I reorganized the code in build script npm library was successfully installed.

Jenkins Slave (service) , cannot detect protractor

We are using slave as service and we r trying to run protractor with simple batch file after calling to npm install , but from some reason protractor was not detected, do u know what could be the reason/problem?
if i use web option (slave) for running job - everything went fine,
BTW - I try to set the service with user that allowed to run the test, and also set node in PATH, but nothing help
Appreciate your comments,
Thanks
Eyal
because you install protractor as a global package, So you should use webdriver-manager from global package install folder. The current folder where you execute npm install -g protractor has no webdriver-manager this cmd/binary. So jenkins report can't find webdriver-manager in current folder or PATH.
For best practice, you should add protractor as your nodejs project's dependency through npm install -S protractor before you write script, after do that, you will found 'protractor' will be add into package.json.
When others who get your source code, he only need to execute npm install under folder where package.json insides to get all dependencies installed.
After npm install done, the webdriver-manager will be found <package.json file inside folder>\node_modules\.bin\webriver-manager
So your cmd should write down as following:
pwd
ls -l "${WORKSPACE}"
cd /d <package.json file inside folder>
npm install
node_modules\.bin\webdriver-manager update
node_modules\.bin\protractor conf.js

How to integrate meteor's velocity tests with jenkins?

On Velocity's GH page it mentions "easy CI integration" as one of the benefits, but I haven't seen any documentation about it.
How can I integrate Velocity with Jenkins?
You should use:
meteor --test
meteor run --test
This does the same thing as the velocity-ci without the extra installation
You could try the velocity-ci
velocity-cli
NPM module for running your velocity test suites from the command-line
Installation
npm install -g velocity-ci
Run
From inside your project directory type velocity
How it works
The velocity-cli spawns a meteor process and connects to it using DDP.
PhantomJS connects to the meteor process to trigger client side tests.
Test results received via DDP are printed at the console. This process
exits with the appropriate exit status code.
So the build step would be velocity inside the meteor directory

Resources