Jenkins

Jenkins is an open-source automation server written in Java(can be used with any technology). Jenkins helps to automate the non-human part of the software development process, with continuous integration.

It works based on plugins, i.e., have to install respective plugins in order to communicate. For example, Maven, Git plugins have to install with configuration.

Instead of pulling the entire code for building and testing. You can just use Jenkins to automatically fetch the code from the repository, build and test it in the test environment and can send an email notification about the results so it will be easier to find the bug in that version of the commit, instead of going through the whole code to find the bug.

Protractor with Docker

Advantages of Jenkins:

  • It is open-source, and it is user-friendly, easy to install, and does not require additional installations or components.
  • Easily Configurable. Jenkins can be easily modified and extended. It deploys code instantly, generates test reports. Jenkins can be configured according to the requirements for continuous integrations and continuous delivery.
  • Platform Independent. Jenkins is available for all platforms and different operating systems, whether OS X, Windows, or Linux.
  • Rich Plugin ecosystem. The extensive pool of plugins makes Jenkins flexible and allows building, deploying, and automating across various platforms.
  • Easy support. Because it is open-source and widely used, there is no shortage of support from large online communities of agile teams.
  • Developers write the tests to detect the errors of their code as soon as possible. So the developers don’t waste time on large-scale error-ridden integrations.
  • Issues are detected and resolved almost right away, which keeps the software in a state where it can be released at any time safely.
  • Most of the integration work is automated. Hence fewer integration issues. This saves both time and money over the lifespan of a project.

test & pretest & posttest

Install Jenkins

1. Navigate to : https://jenkins.io/download/

2. Download the Generic war files, choose the war file from the stable release
jenkins-generic-war-file 3. Go to the folder in terminal/CMD where you have stored the Jenkins.war file and execute the below command.

java -jar jenkins.war

4. You would be able to success screen once we execute the command.
5. Navigate to the URL in your browser http://localhost:8080; sometimes, it may take up to 3 minutes to open the page, so have patience if you get no page/ error page.
6. Please navigate to the highlighted path in your browser, and copy the password. unlock-jenkins-selenium 7. Install / select plugins based on your need, you can install plugins after installation of Jenkins as well. select-install-jenkins-plugins 8. You may need to wait for 10-15 mins for the completion of the installation of plugins. installation-of-plugins-jenkins-selenium 9. Fill the use details and continue fill-user-details-jenkins 10. Click on start Jenkins button start-jenkins 11. If you reached the below page, then your installation is successful. home-jenkins

Protractor Interview Questions

Jenkins Protractor Integration

    1. Open Jenkins using http://localhost:8080/
    2. Click on New Item
      jenkins-protractor-new-project
    3. Enter Job Name and Choose Free Style Projectfree-style-protractor-project
    4. Choose advanced options under the General sectiongeneral-sectionjenkins-custom-workspace
    5. Enter the folder where your protractor conf file is presentcustom-workspace-jenkins-protractor
    6. Now Add a Build Step and Choose Execute Windows Batch Commandadd-build-step-jenkins-protractor
    7. Provide the command to run the protractor, protractor conf.js. If you have not configured the workspace path, then you need to write the command to navigate to the workspace and then protractor run command like below.
      d: # change the driver to d
      cd D:Protractor Demo # navigate to the folder where the conf file is present.
      protractor conf.js
    8. Save the configuration and Click Build Now Linkbuild-jenkins-protractor
    9. Now you will be able to see the execution, under console inside the instance number

Errors in Protractor

Fetch code from Repository

Not all the times, you will have to run in the local machine because you got to execute the automation in node/slave machines.

In such cases, we have to fetch the code from the repository and execute if your code Javascript then you can run directly, but if it is Typescript then you need to compile the code(tsc) and then run it.

build-info-jenkins Under Source Management, choose the required tool and then provide the git URL and then the branch to clone. git-repository-source-management-git You might need to change the build steps because this time, you should install the npm packages and then compile the code and then execute.

d: # change the driver to d
cd D:Protractor Demo # navigate to the folder where the conf file is present.
npm install protractor
#please do install required, I have limited with protractor to show you
tsc
protractor conf.js

Timeouts in Protractor

Jenkins with Package JSON

You might have heard about the Maven build tool used for installing the java jar files and update them.

But with javascript, we should use the package.json file to install npm packages at a shot; please refer package.json tutorial for more details.

package.json file must be pushed and should present in the repository

I have set the compilation command in the postinstall command inside the package.json. Example for package.json

{
  "name": "cherchertech",
  "version": "1.0.1",
  "description": "this is to showcase the package.json tutorial",
  "main": "index.js",
  "dependencies": {
    "jasmine": "^3.2.0"
  },
  "devDependencies": {
    "@types/jasmine": "^2.8.8",
    "jasmine": "^3.2.0",
    "protractor": "^5.4.1",
    "typescript": "^3.0.3"
  },
  "scripts": {
	"preinstall":"npm cache clear",
	"postinstall":"tsc",
	"test": "protractor conf.js",
	"posttest":"rmdir node_modules"
  },
  "keywords": [
    "cherchertech",
    "package",
    "tutorial",
    "protractor"
  ],
  "author": "karthiq",
  "license": "ISC"
}

When we use package.json, we can write below simple steps to install packages and run the code. Repository steps remain the same

d: # change the driver to d
cd D:Protractor Demo # navigate to the folder where the conf file is present.
npm install
npm test

Learn to create package JSON

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • Reply
  • Ravisai
    Hi, I have angular project in my local in that i have created my test cases in E2E folder when I'm running my test cases with the command ng e2e then I'm getting EPIPE error message then I tried running Yarn e2e then my test cases are running. How to integrate with the Jenkins and how to run my test cases when there is a deployment? Can anyone help me on this.
    Reply
  • Kiran
    Hi sir,
    How can we add the build no to access the report in mail for each Jenkins run.
    Reply
  • Sowjanya
    Hi KarthiQ, 
    
    i have gone through the protractor material you have provided and that is awesome. Actually i am working on protractor with minimum knowledge since i have not come across such scenarios to lean more. But now after reading this tutorial i am confident enough to handle any scenario. Thanks a lot.
    
    i got confused in one area that all the examples given is in only typescript?? do you have any material with only javascript ? 
    Reply
    • Author
      Sowjanya,
      Code for Javascript is same except where I used class keyword
      Reply
      • Sorry KarthiQ, I did not get your answer. Can you please elaborate.
        Reply