Jenkins

Jenkins is an open source automation server written in Java. Jenkins helps to automate the non-human part of 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 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 commit, instead of going through the whole code to find the bug.

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 projec

Install Jenkins


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

2. Download the Generic war files, choose the war file from the stable relaese
jenkins-generic-war-file 3. Go to the folder in terminal/CMD where you have stored the jenkins.war file and execute 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 a it may take upto 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 completion of installytion of plugins. installation-of-plugins-jenkins-selenium 9.Fill the use details and contunie fill-user-details-jenkins 10. Click on start jenkins button start-jenkins 11. If you reached below page then you installtion is successsful. home-jenkins

Single Inheritance in Selenium and java

Run Selenium with Batch file

Create a selenium sample test using TestNg as unit testing framework, and create testng.xml. Below is the same test file we have created :


							public class TestJenkins {
								@Test
								public void openGoogle() {
									
									System.out.println("Test  Started");
									System.setProperty("webdriver.chrome.driver", "D:\\Eclipse progs\\driverserver\\chromedriver.exe");
									
									System.out.println("open browser");
									WebDriver driver = new ChromeDriver();
									driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
									
									System.out.println("open google");
									driver.get("http://google.com");
									
									driver.quit();
									System.out.println("Test Ended");
								}
							}			
							


Once you crate the testng.xml file, place the below jars under "jars" folder:
1. testng
2. Jcommander
3.Selenium standalone server.

jars-selenium-testng-jcommander

Now execute the below command in the cmd/terminal to open run the test case, you must be inside the project folder with cmd i.e where you have the .classpath file.


							java -cp Class_Files_Path; Jars_Path org.testng.TestNG testng.xml
							java -cp bin;jars/* org.testng.TestNG testng.xml			
							


cmd-run-testng-selenium

If you command line execution is successful, then add the same line into the notepad and save the file as run.bat

Now try to run the bat file by double clicking, it should perform same operations like cmd execution.

Set Jenkins Job

Open jenkins and select 'New Item' new-item-jenkins-selenium

Enter the Job name, and Select Free Style project and click ok button. free-style-selenium

Select Custom workspace under General section and provide the project folder details. custom-workspace-jenkins-selenium

Under Build Section, choose Execute window batch command and provide our batch file name. build-cmd-jenkins-selenium

Click Save button, jenkins now will open the home page.

Click the Build Now link to run our project in Jenkins build-now-jenkins-selenium

Once the Jobs starts Heart beat starts, orange sphere is the heart beat and the Green arrow is Build Name. heart-beat-jenkins

Now click the build number to see the details, and select Console Output option output-jenkins-selenium

If you compare above output, it will exactly match with the output occured when we ran with cmd.

Lets learn how to add some colorful results to jenkins rather than console log summary.

Jenkins Plugins

Jenkins provides all the standard operations and if we want to have more options like reposting, something like theat then we should install the plugind for the jenkins.

plugins-jenkins-selenium

Go to Available tab and search for TestNG; you may get result for TestNG results, select it and install testng-results-plugin-jenkins-selenium

If your installtion is successful then you may see the success information like below testng-result-success-jenkins

Generate Report in Jenkins

Once the TestNG plugin is installed the Choose to confugure the Build. configure-result-jenkins-selenium

Go to Post Buils option and select Publish TestNG results, it may populate default values of it. In advanced section you can make the build as unstable, if a test fails. post-build-actions-jenkins

Save the changes made so far.

Run the project again using Build Now Link, refresh the Page testng-results-selenium-jenkins

Click the TestNG Results and select the Bulild Number, now it will navigate to result page. result-jenkins-selenium

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech