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.
1. Navigate to : https://jenkins.io/download/
2. Download the Generic war files, choose the war file from the stable relaese
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
6. Please navigate to the highlighted path in your browser, and copy the password.
7. Install / select plugins based on your need, you can install plugins after installation of jenkins as well.
8. You may need to wait for 10-15 mins for completion of installytion of plugins.
9.Fill the use details and contunie
10. Click on start jenkins button
11. If you reached below page then you installtion is successsful.
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:\\PATH\\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("https://google.com");
driver.quit();
System.out.println("Test Ended");
}
}
Once you crate the testng.xml file, place the below jars under "jars" folder:
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
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.
Open jenkins and select 'New Item'
Enter the Job name, and Select Free Style project and click ok button.
Select Custom workspace under General section and provide the project folder details.
Under Build Section, choose Execute window batch command and provide our batch file name.
Click Save button, jenkins now will open the home page.
Click the Build Now link to run our project in Jenkins
Once the Jobs starts Heart beat starts, orange sphere is the heart beat and the Green arrow is Build Name.
Now click the build number to see the details, and select Console Output option
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 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.
Go to Available tab and search for TestNG; you may get result for TestNG results, select it and install
If your installtion is successful then you may see the success information like below
Once the TestNG plugin is installed the Choose to confugure the Build.
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.
Save the changes made so far.
Run the project again using Build Now Link, refresh the Page
Click the TestNG Results and select the Bulild Number, now it will navigate to result page.
SO for you are working in Master, now lets try to setup the lsave machine for this master so that we can run multiple jobs at same time.
Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know.
Knowledge is the only thing that doubles when you spend it.
I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation