Have you ever seen Jenkins with selenium? Welcome to Jenkins post we have seen so many things in the last post about maven integration and GitHub integration now let us create a build and run through Jenkins. Before moving to integration, part let’s have a short intro about Jenkins
Selenium with Jenkins Integration
Jenkins with Maven and Selenium
What is Jenkins
- Jenkins is an open source continuous integration tool which is written in Java
- Jenkins was originally developed as the Hudson project. So if you ever see Hudson then it will be known as Jenkins CI Tool. Hudson’s creation started in summer of 2004 at Sun Microsystems. It was first released in java.net in Feb. 2005.
Jenkins with Selenium
- When your test cases are ready and you want to handover to the client or manual testing team so that they can trigger these test cases using single click then Jenkins is the best choice.
- Using Jenkins we can create a build (Build – set of Test case combined together) and we can run easily using a batch file or Git or build.xml or SVN etc.
- In Jenkins, we can schedule the build periodically
Example- You want to run 100 Test case daily at 10 pm then Jenkins will take care of this based on our pattern it will trigger your build
- Email-Notification- Jenkins provide notification emails to once build passed or failed to respective recipients (Depends on t configuration)
Before starting if you have been having Eclipse , TestNG and if you are using Excel sheets or CSV then these jars should be ready.
We will divide full tutorial into the following section.
1- Download Jenkins (War file)
2- Configure Jenkins for Running Build (Configure Java,Email notification)
3- Execute Selenium build using Jenkins (Using batch command)
4- Schedule Jobs in Jenkins to run periodically using cron pattern.
We can integrate Jenkins with Selenium, Maven, Git, Github and other tools we can like Sahi, Telerik etc.
So lets start Jenkins Integration with Selenium
RANJAN V says
Hi Mukesh,
How to Run Automation Scripts in Jenkins based on Cron Expression Pattern?
Mukesh Otwani says
Hi Ranjan,
Please check this link https://support.acquia.com/hc/en-us/articles/360004224494-Cron-time-string-format
RANJAN V says
Thanka a lot)))
Hariprakash says
Hi Mukesh, How to update Pass/Fail results for testcases in Jira through Jenkins. I am testing Web based application, Jenkins job has to run and it should update the result as Pass / Fail in Jira automatically and also i want to update the reports with screenshots in Jira.
Mukesh Otwani says
Hi Hari,
For this, you need to go through JIRA APIs’ which will describe about how to call update status from you selenium script.
madhu says
Hi Mukesh,
We are executing the scripts through jenkins , jenkins will take latest code from github.
here my problem is jenking is connecting github but it is saying “Repository not found.” and returned status code 128.
Mukesh Otwani says
Hi Madhu,
Did you check through which user in Jenkins, the code is getting cloned? Moreover, login to the corresponding machine (where you want to clone code), do ssh to github and check the status of command.
vimal says
Hai Mukesh
can you guide me how to set run testcases in particular time using jenkins
Mukesh Otwani says
Hi Vimal,
Under Build Triggers, you will be able to see Build Periodically, there you need to set cron job pattern. For CRON job, check this link https://en.wikipedia.org/wiki/Cron
Karthik says
Hi Mukesh,
Great job! Helping the QA Community with your knowledge sharing post/videos.
Can you please let me know how we can pull our latest code from Tortoise SVN to Jenkins,so that the automation scripts we run will be updated each time.
Mukesh Otwani says
Hi Karthik,
You can define SVN details under ‘Source Code Management’ header followed by selection of Subversion option.
Siddhartha says
Hi Mukesh,
How can I see the UI (i.e Browser opening) while executing Selenium files using Jenkins.
Mukesh Otwani says
Hi Siddharth,
If your Jenkins slave is master or another which is not connected through Launch slave agents via Java Web Start then all scripts will run in headless mode. So I would recommend you to connect slave through Java WebStart way. Also refer this link https://wiki.jenkins.io/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines+on+Windows
RAJENDRA Narayan Mahapatra says
Hi Mukesh, could you please show Jenkins configuration with latest version of Jenkins? As the UI has completely got changed.
Mukesh Otwani says
Hi Rajendra,
As per my observation, UI is almost same only the way of organisation of various features are now categorized.
I am also planning to post for new Jenkins. I ‘ll do it soon…:)
RAJENDRA Narayan Mahapatra says
Hi Mukesh,
Can you please show the steps for configuring extent report and html report (TestNg) in Jenkins? It will be very useful…..
Mukesh Otwani says
Hi Rajendra,
Please go through this link http://learn-automation.com/advance-selenium-reporting-with-screenshots-2/
Shiva says
Hi Mukesh,
Your way of teaching and your videos are awesome. Really it is helping a lot for many guys like me. keep up the Good work. Hats of to you..!!
Thanks
Shiva
Mukesh Otwani says
Hi Shiva,
Your comments made my day…I’ll always try my level to solve doubts and queries of blog subscribers.
Very very thanks Shiva…:)
Mallik says
Hi mukesh This is Mallikarjun…Iam learning alot from YOur Videos.Your Videos are very simple and understandable for everyone..It helps alot for all the Automation learners.Thank you very much Mukes..Please keep sharing your fabulous work like this…
Mukesh Otwani says
Hi Mallik,
Very very thanks for your appreciation…:)
Feel free to ask your doubts in my blog, I’ll try my level best to answer your queries.
Harikrishna says
Hi Mukesh,
Can i use TFS instead of Jenkins? If yes could you please explain briefly?
Mukesh Otwani says
Hi Hari,
Yes, you can because TFS is a proprietary tool which has all features for a version controlling, build dependency, CI/CD environment. But sorry to say that I never worked with this tool so can’t say anything about its configuration part.
Ramyashree Bhat says
Hi Mukesh, how can we do Jenkins-Extent report integration? I guess we need to use HTML Publisher plugin for that… But I’m struggling with the configuration ..could you please help?
Mukesh Otwani says
Hi Ramyashree,
Please refer this link https://wiki.jenkins.io/display/JENKINS/HTML+Publisher+Plugin
jino says
Using Jenkins , the code is running in our local machine..Right?……Can we done in a Cloud
Mukesh Otwani says
Hi Jino,
Yes, you can connect/configure jenkins with cloud based machine also.
Balaji says
Hi Mukesh
JDK option is not available in configuration of jenkin……….
can i execute my test case without configuration
Mukesh Otwani says
Hi Balaji,
You need to provide JDK path in jenkins otherwise jenkins can’t find it.
Pranay Agarwal says
Hi Balaji,
You can find JDK option in Manage Jenkins –> Global Tool Configuration
Anji says
Jenkins job is failing with message like “run.bat” is not a recognized as a interal or external command, operable program or batch file… then exit 9009…. Any idea on how to resolve
Mukesh Otwani says
Hi Anji,
Have you restarted your machine after setting path for Apache Maven.
After restart, if issue is still same then install Maven 3.1.1 and restart machine followed by mvn command execution.
Sumeet Kumar says
Hello Sir,
I need your help on this,
how to find out spelling mistakes by using selenium in any website is there any way?????
Mukesh Otwani says
Hi Sumeet,
Use assertions for comparing characters in a string.
snehal says
Hi Mukesh,
Would you pls help me on this?
I have tried so0 many times installing testNG add-on through eclipse marketplace, but everytime i get this msg
“Unable to connect to repository http://beust.com/eclipse/content.xml
Connection timed out: connect”
I m using latest Eclipse-oxygen version.
can you pls help with other ways to installing it?
Mukesh Otwani says
Hi Snehal,
Yesterday also, I installed testng into my new eclipse instance from marketplace. The issue which you are facing might comes in organisational network due to which network firewall doesn’t allow unsigned applications to get install in machine or network connectivity issues.
snehal says
Oh ok, hmm yeah i agree with you of firewall – unsigned issue..that might be the case. But hey, i found a way around and its successfully running TestNG.
thanx for your instant reply and all your videos are great and makes selenium easy to learn.
Mukesh Otwani says
Hi Snehal,
That’s great..:)
May I know, how you solved it…
Rajesh Thakur says
I also did little R&D and got the new way to install TestNG.
Download separate TestNG jar files. and integrate them with eclipse’s.
Once you download the Jar files, extract the zip file. It will contain two folder (Feature and plugin) each containing 2 jar files. Add those jar files in eclipse’s feature and plugin folder respectively. Restart eclipse.
Mukesh Otwani says
Hi Rajesh,
Very very thanks for sharing this info. This will surely help other readers also.
Surendar says
Hi Mukesh,
what is the best tool to test rest API’s?
Mukesh Otwani says
Hi Surendar,
Go with Rest Assured http://rest-assured.io/
Arvinder says
Hi Mukesh,
Thanks a lot for sharing knowledge. Can you please upload more videos on Jenkins showing different features of Jenkins.
Mukesh Otwani says
Hi Arvinder,
I’ll do it soon…:)
krishna says
Hi Mukesh,
Thank you so much for valuable information you have shared so far and i have managed to learn a lot from you videos.
please can you assist me with regards to the below
i am able to generate cucumber reports and able to send them through jenkins successfully, but the issue that i am facing is with the cucumber reports.
The reports that i am receiving are in plain text and graphs are missing.
i have updated the content type to “Both HTML and Plain Text” under Editable Email notification section.
kindly can you suggest me if i am missing any other settings
Mukesh Otwani says
Hi Krishna,
Is it broken CSS on report ?
Krishna says
Hi Mukesh,
Please execuse my ignorance,
I am very new to Jenkins. I did not understand your question.
Krishna says
Hi Mukesh
Yes it looks like broken CSS on the email, as I can see the cucumber reports getting successfully generated under the build folders but the same report when I am sending via Jenkins, I am missing the formats in the mail which i am receiving(graphs, colours )
Regards
Krishna
Mukesh Otwani says
Hi Krishna,
There is no such setting to fix CSS broken issue. Have you tried Extent Report V3?
Krishna says
Hi Mukesh
Thank you so much for the messge
Please can you let me know where can I find the detials of Extent Report v3.
Or can you please advise me on the below
Is it possible to send cucumber reports as an attachment via Jenkins, as the cucumber reports are getting generated in build folder.
Kindly can you guide me please
Regards
Krishna
Mukesh Otwani says
Hi Krishna,
For Extent Report V3, you can go through this link http://extentreports.com/docs/versions/3/java/
yes, it is possible, you can take report link from Jenkins jobs’ workspace
surya ramtej says
hi Mukesh,
Iam new to Jenkins. as i am using the codebeamer for manualtesting and i would like to learn the automated testing and integrate the codebeamer with selenium via jenkins. i have very less programming language in Jenkins. So can you help me with the following queries. Looking forward for your reply.
Regards,
Surya
Mukesh Otwani says
Hi Surya,
As per my observation, codebeamer is a proprietary ALM tool for which I don’t have any license. So as of now, it is not possible me but I’ve added this into my wishlist.
Anoop sharma says
Hi Mukesh
I need your help regarding parameterized build creation from jenkins.
I want to upload file (.xlxs) from jenkins , which i done, but now how can i use this in our code. i need to take input from this xls file and take action accordingly.
i declare path of this file in constant.java file and i used it in my logic. please help me out.
Mukesh Otwani says
Hi Anoop,
If you are able to get path of excel file then read/write operation is not tedious job. Please check this link http://learn-automation.com/read-and-write-excel-files-in-selenium/
bharath says
Hi Mukesh ,
i am new to jenkins , is it required to set up jdk in jenkins and i will be using git . i give me selenium project path as the repository and also give the path of the pom .
is there any thing else i need to configure
Mukesh Otwani says
Hi Bharath,
JDK is used to compile your java files which comes as bundled with jre. Git will help you to bring latest code from repo.
Pranav Pund says
Hi Mukesh,
Could you please explain us what set up we need to do in Jenkins if we need our test to be triggered automatically once developer checks in code in SVN? In your video you have shown how to run our Automated tests at particular time using CRON Pattern, but it would be really helpful if you could explain us what set up we need to do in Jenkins if we need our test to be triggered automatically once developer checks in code in SVN?
Mukesh Otwani says
Hi Pranav,
For SVN, there is a plugin being mentioned on this link https://wiki.jenkins.io/display/JENKINS/Subversion+Plugin
This page contains configuration for polling to svn repo.
Anoop shrama says
Hi Mukesh
I want to run my java code (selenium script ) via jenkins , and jenkins is setup on iOS. so can you telll me how can i run my script via jenkins. i am not using Test NG so no XML are there.
Mukesh Otwani says
Hi Anoop,
In this case, you java file should have main method. On Mac, you execute your code via Execute Shell section inside jenkins job configuration via navigate to required folder then javac filename.java followed by java filename…thats it.
Anoop sharma says
Thanks for reply , yes i have main method in my DriverScript.java file, but i dont have too much knowledge about Jenkins , can you let me know in detail how can i create Shell executable and configure in jenkins ,or it would be good if you give me any reference so i can set up my project and test it, if all goes well i ll deploy on my server.
Mukesh Otwani says
Hi Anoop,
Check this link
palanisamy says
hi, mukesh how to do api testing using selenium with java in automation.
Mukesh Otwani says
Hi Palanisamy,
Selenium itself is an API which allows us to interact with Web page controls. And Selenium deals only with controls of web page.
Harikrishna says
Hi Mukesh,
Can you please explain about MAVEN AND GITHUB Briefly?
and also explain the difference between MAVEN AND GITHUB and JENKINS Briefly?
Mukesh Otwani says
Hi Harikrishna,
In brief….
Maven is build dependency(to fetch dependency and adding those to project build path)
GitHub is for code repository(to secure your source code to some location)
Jenkins is for execution(to execute your script at particular time based CI/CD strategy defined by project)
harikrishna says
Thanks Mukesh
Harikrishna says
what is the difference between Implicit Wait and Explicit Wait and Fluent wait?
If possible can u plz explain the above with sample code?
Mukesh Otwani says
Hi Hari,
Please refer these links. Forth link is kind of addon which could be used in framework
1. http://learn-automation.com/explicit-wait-in-selenium-webdriver/
2. http://learn-automation.com/implicit-wait-in-selenium-webdriver/
3. http://learn-automation.com/fluentwait-in-selenium-webdriver/
4. http://learn-automation.com/best-way-to-handle-synchronization-in-selenium-webdriver/
Harikrishna says
Thnx
Gaurav says
Hello Mukesh,
Thanks for sharing in depth of Jenkins knowledge and setup.
I have a question : Why we should use Jenkins in Selenium.
I am able to run my Test through TestNG by simple doing rightClick on TestCase.
Just for a minute forget about email notification advantage , Then i am not able to figure out the main use in selenium.
Generally in our organization we are updating code on local machine and then we use to checkin through SVN. So this question is always hitting me why to use Jenkins.
I have gone through various websites to find this answer but did not get satisfactory answer.
Mukesh Otwani says
Hi Gaurav,
As you told that you are executing your script by yourself that means everytime script execution requires human intervention. Now think about a situation, when you want to trigger hundreds of scripts at particular time of day so that by end of day you can see results of execution. This is where, Jenkins plays its role….
Jenkins can execute scripts at given time. It will fetch latest code from SVN and then it can execute latest code. This is just an intro for a jenkins wrt your usage. If you look at broader level then jenkins plays an major role in Continuous Integration/Continuous Delivery scenario.
Nigam says
Hi Mukesh, My jenkins runs in linux box and my testing team wants to run selenium test in real browser. How do I set up this? Do I need to create a new Windows Slave and run selenium Tests there? Please advise…
Mukesh Otwani says
Hi Nigam,
If your script is being created for linux environment(here environment is referring to driver executables which differs for linux & windows) then run it on same machine where Jenkins has been hosted. If scripts are for windows environment then connect a windows slave to jenkins and execute script on slave itself.
Nigam says
Hi Mukesh- Currently my slave is running as windows service, and I guess that is blocking selenium to launch chrome browser. I can see that chrome.exe and chromedriver.exe has launched in the background(from task manager) though. How do I handle this?
Mukesh Otwani says
Hi Nigam,
This is jenkins usual behavior. If slave is running as windows service then web browser tests always run in headless mode. But in headless mode, it runs well. And if you want to see execution by your eyes then don’t configure slave as Windows service.
Bala says
Hi Mukesh,
I am getting an error “Firefox can’t establish a connection to the server at localhost:8080”. How do I proceed with this? Could you please help me out at earliest?
Mukesh Otwani says
Hi Bala,
Please tell me which version of FF, GeckoDriver, Selenium are you using?
tribhuvan says
Hi Mukesh,
I want to use Selenium With Cucumber for writing my test scripts. Can I use the Jenkin in this case. As per your demo , you use the TestNG . is there any possibility use the jenkin in my case as well.
Mukesh Otwani says
Hi Tribhuvan,
Jenkins is CI/Cd integration tool. It help you to execute your test script with given parameters in remote machine without human intervention. Jenkins is capable of doing lot of other stuffs too.
And remember, Jenkins is nowhere related to TestNG. You can use Jenkins at anywhere.
nataraja k b says
Hi Mukesh this is Nataraj. i am trying run localhost:8080. bur it asking for Username and password? may i know how to get username and password?
Mukesh Otwani says
Hi Nataraj,
Go to .jenkins folder in Users folder then open config.xml. Look for useSecurity tag and make its value as false. Exit cmd of jenkins and rerun it.
nataraja k b says
Thank you Mukesh……..
Mukesh Otwani says
…:)
Nithya says
Hi Mukesh, I have invoked jenkins using the command “java -jar jenkins.war”. Still, Selenium scripts are running in headless browser. Plz tell me how to execute the testscripts using chrome browser through jenkins. Thanks in Advance!
Mukesh Otwani says
Hi Nithya,
By default, execution runs of master node itself and that too in headless mode only. If you want to see execution then create a new node from Manage Nodes option. Point newly created node to same machine i.e the machine where Jenkins server has been hosted.
Nagendra says
I’m getting below error in WEB after typing localhost:8080
Unlock Jenkins
To ensure Jenkins is securely set up by the administrator, a password has been written to the log (not sure where to find it?) and this file on the server:
C:\Users\Deepa\.jenkins\secrets\initialAdminPassword
Please copy the password from either location and paste it below.
Administrator password
——————————–
If i go to that path im not able open that file because it is a KEY file
Mukesh Otwani says
Hi Nagendra,
Open it with Notepad
Asmita says
Hello Mukesh,
I have tried below code
java -jar jenkins.war
it’s not work
thought may be port 8080 is occupied so tried below
java -jar jenkins.war -httpport=8081
still same error
please help me to solve this problem.
[0mMar 25, 2017 11:00:40 PM jenkins.model.Jenkins$21 onAttained
INFO: Completed termination
Mar 25, 2017 11:00:40 PM jenkins.model.Jenkins _cleanUpDisconnectComputers
INFO: Starting node disconnection
Mar 25, 2017 11:00:40 PM jenkins.model.Jenkins _cleanUpShutdownPluginManager
INFO: Stopping plugin manager
Mar 25, 2017 11:00:40 PM jenkins.model.Jenkins _cleanUpPersistQueue
INFO: Persisting build queue
Mar 25, 2017 11:00:41 PM jenkins.model.Jenkins cleanUp
INFO: Jenkins stopped
Mukesh Otwani says
Hi Asmita,
If you are using windows environment then try this installer
Asmita says
please help me.
It’s not working.
what’s problem with cmd??
Mukesh Otwani says
Hi Asmita,
Installer link which I sent was a workaround only if you are running with shortage of time. Use netstat -a in cmd and check which port is free
Asmita says
It shows status Listening
What should I do?
Thanks for your reply
Mukesh Otwani says
Hi Asmita,
Try to install jenkins with free port number.
sumanth says
Hi mukesh, I ‘ve configured Jenkins in my PC earlier. So forgotten my USER ID: tried couple of ways to find it. But unable to get the user id. can you help me out?
Mukesh Otwani says
Hi Sumanth,
Navigate to folder users-> login user folder-> .jenkins , the open config.xml and set false value against tag. Close cmd and again run java -jar jenkins.war
If you have installed it as windows service then navigate to jenkins installation folder and edit config.xml in same way which I’ve mentioned above.
Sankalp varadkar says
logger.log(LogStatus.FAIL, “Title Verification”, image); } report.endTest(logger); report.flush();
Mukesh Otwani says
Hi Sankalp,
Use this -> logger.log(LogStatus.FAIL, image);}
report.endTest(logger);
report.flush();
Ashwini says
Hi Mukesh ,
I have downloaded jenkin war file, when i open the jenkin configuration i don’t see fields of jdk and maven configuration on localhost:8080.
How should i rectify this.
Mukesh Otwani says
Hi Ashwini,
If it is Jenkins 2.xxx then check settings under Global Tool Configurations.
Sindhu says
Hi Mukesh,
I configured a job in Jenkins and in the Build i gave the .bat files details in Execute windows batch section. While triggering the build i could see the execution output in the console , but i could’nt see any browser opening.
I have done the jenkins setup using .msi file.
What should i do to see the gui of the browsers?
Thank you
Mukesh Otwani says
Hi Sindhu,
If you are running Jenkins slave as service then you won’t be able to see execution. Run on slave machine as JavaWebStart
Shruti says
Hi Mukesh,
I have downloaded latest jenkin file from the website. After download, it asked me to install preferred plugins or customized plugins. I went with automatic i.e mainly preferred plugins.
But the problem is I am enable to see JDK configuration in configuration system of manage jenkins tab. Please help
Mukesh Otwani says
HI Shruti,
You can find in Global tool configuration.
lokesh says
I am unable to configure emails in Jenkins
Mukesh Otwani says
What issue Lokesh?
amit says
Nice man I saw your selenium video , its very helpful , thanks a lots for sharing such a valuable knowledge
Mukesh Otwani says
Thank you AMit. Keep in touch.
Chitra says
Hi Mukesh, I downloaded Jenkins 2.19.1 in windows 10 and executed cmd : java -jar C:/Jenkins.war
But I get below error saying Jenkins is stopped:
Can you please help me on what I need to do for Jenkins to work. Thanks in advance
webroot: $user.home/.jenkins
Oct 17, 2016 11:40:49 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @602ms
Oct 17, 2016 11:40:49 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Oct 17, 2016 11:40:52 AM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Oct 17, 2016 11:40:52 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-9.2.z-SNAPSHOT
Oct 17, 2016 11:40:54 AM jenkins.model.Jenkins _cleanUpShutdownPluginManager
INFO: Stopping plugin manager
Oct 17, 2016 11:40:54 AM jenkins.model.Jenkins _cleanUpPersistQueue
INFO: Persisting build queue
Oct 17, 2016 11:40:54 AM jenkins.model.Jenkins cleanUp
INFO: Jenkins stopped
Mukesh Otwani says
Hi Chitra,
In your system 8080 port is occupied. Kindly start the Jenkins in other port
java -jar jenkins.war –httpPort=8081
Chitra says
Thanks Mukesh, it worked
Mukesh Otwani says
Cheers Chitra