I struggled with how to post this tutorial on Jenkins. I didn’t want to be too short and incomplete that it lacked important information and I didn’t want to be too long winded that no one finds it useful. It is my hope that others will find some use in this article. It combines a lot of information from various sources that I had to hunt around to find. Even I won’t know how this post goes until I finished writing it.
I am learning about automated testing for my job, in particular, Java Selenium with Cucumber. So far, it has ignited a passion for work that I have not felt in a long time. I hope that, as I learn, I can share with those wanting to read more about automated testing; I am learning with you, the reader. So, without further ado, here we go.
The basic Jenkins setup needs the following in order to work. Most of this will be done from the command line as it would likely be set up on a headless server.
- Ubuntu 15.04 (Installation not covered in this article)
- Java JDK (1.8 recommended)
- Selenium Server
- Headless browsers
- Separate Chrome driver
Installing the Java JDK is simple from the Ubuntu command line.
- $ sudo apt-get update
- $ sudo apt-get install openjdk-8-jdk
And that is really all there is to it. Once the jdk is downloaded and installed, its time to move onto the next step.
Maven is just as simple to install as the Java JDK was.
- $ sudo apt-get update
- $ sudo apt-get install maven2
Like before, thats all there is to it. Moving onto the next prerequisite, we will have to do a little bit more work. Its not bad, so its time to roll up our sleeves and dig in.
- Go to: http://docs.seleniumhq.org/download/
- Select the latest Java version to download
- Place the server in a relevant location such as /var/lib/selenium/
That wasn’t too bad now, was it. As we move on, things start to get a little more complicated but I promise you that you can do this; its not as bad as you think.
The headless browsers
The headless browser installation looks a little scary, but its not too bad. I will try to explain each of the steps as best I can as we do them. The commands to enter into the terminal will be first, followed by the explanation.
- $ wget -q -O – https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add –wget is a command to go out to the internet and fetch an element. Most often you will see it used to download files from the command line of a terminal. In this case, we are using it to install the public key for the Google apt repository that houses the Chrome web browser. The -q option turns off verbosity to the shell output and the -O concatenates all the information together into one file. In a nutshell, this installs the key to your apt repository. More information
- sudo sh -c ‘echo deb http://dl.google.com/linux/chrome/deb/ stable main > /etc/apt/sources.list.d/google.list’This command adds a line to the local apt repository for the chrome browser to be installed in the next step. It compliments the command from the previous step. The ‘sh’ is the shell command. The -c reads commands from the string instead of from the standard output. The greater than sign (>) is a pointer to write the text ‘debhttp://dl….etc’ to a file. More information
- sudo apt-get update && sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic xvfb x11-apps imagemagick firefox google-chrome-stableDon’t be intimidated. The command here installs items needed for the browsers to run in headless mode as well as the browsers themselves. The first part of this command (sudo apt-get update && sudo apt-get install -y) is actually two commands put together; apt-get update and apt-get install. The -y answers yes to all confirmation dialogs. The rest of the command is a shopping list of sorts for the apt-get install command; these are the items that will be installed. More information
Even though we installed Chrome in the previous step, Selenium WebDriver needs to have a separate driver installed to run the Chrome browser. This small file can be downloaded here. Once downloaded, we need to put it in some sort of logical location. I put my copy in a folder called ‘drivers’ in the Jenkins folder (/var/lib/Jenkins). Once the file is safe in its new home, we need to be sure to make it executable. We do this by executing the following command:
- $ sudo chmod u+x /path/to/chromedriver
Git is a version control system that is used for software development. It has a similar function as SVN, but its an entirely different and lighter-weight system. The technical explanations are outside the scope of this article so I will skip them.
It is important to know that we are not installing the repository itself, but rather the client so that Jenkins can connect to Git and grab the source code we want to test.
Installing Git is as easy as the first two items we installed. It is done in the following manner:
- $ sudo apt-get update
- $ sudo apt-get install git-core
Now that that is done, it is time to move onto the main course, installing Jenkins.
After having all of our prerequisites installed, we can now install Jenkins.
- wget -q -O – https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add –
- sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’
- sudo apt-get update
- sudo apt-get install Jenkins
I am not going to go into the details of the commands here as they have been explained earlier in this article. If everything was done correctly, Jenkins should now be installed. You can verify this by going to the URL for Jenkins in your favorite browser:
As I mentioned in the opening of this article, I did not know how I was going to end it but now I think this is the perfect place… for now. Look forward to an article in the near future about configuring Jenkins to run automated Selenium tests.
Thanks for reading.