Setup & Run Jenkins Job with Selenium Project on AWS EC2 Linux Server

In this tutorial, you will learn the following:

– Configure Jenkins Job on AWS EC2 Linux Server

– Build Selenium Java Maven project from Github

– Setup Chrome Driver and Binary on EC2 Linux Server

– Run Selenium Tests on Chrome Headless Browser

Prerequisites:

1. AWS EC2 instance is running. (Follow here)

2. Connect to your EC2 instance with SSH. (Follow here)

3. Setup a Jenkins Build Server on AWS EC2. (Follow here)

Steps to install and configure Java, Maven, Git on AWS EC2 Linux Server

1. Update Java on AWS EC2 Linux Server

Run the below command to install latest version of Java

sudo amazon-linux-extras install java-openjdk11

Run the below command to show all the different Java versions installed on the AWS EC2 Linux Server.

update-alternatives --config java

Choose the latest Java version from the given options.

2. Set the Java Environment Variable on AWS EC2 Linux Server

Run the below command to edit the .bashrc file

vim .bashrc

Enter the below lines in the .bashrc file and save the file

export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-11.0.7.10-4.amzn2.0.1.x86_64"

PATH=$JAVA_HOME/bin:$PATH

Run the below command to apply the changes

source .bashrc

3. Install latest version of Git on AWS EC2 Linux Server

sudo yum install git -y

4. Install latest version of Maven on AWS EC2 Linux Server

Add a repository with a Maven package:

sudo wget https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

Enter the following to set the version number for the packages:

sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo

Install Maven:

sudo yum install -y apache-maven

5. Install latest Chrome Driver on AWS EC2 Linux Server:

sudo wget https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver

6. Install latest Chrome Binary on AWS EC2 Linux Server:

sudo curl https://intoli.com/install-google-chrome.sh | bash
sudo mv /usr/bin/google-chrome-stable /usr/bin/google-chrome

Steps To Configure Java, Maven, Git on Jenkins

1. Configure Java on Jenkins

Goto Manage Jenkins -> Global Tool Configuration -> JDK Installations -> Add JDK

Uncheck the option “Install Automatically”

Add a Name – “Default”

Run the following command in AWS EC2 Server to find the JDK path:

readlink -f /usr/bin/java

Add the JDK path in JAVA_HOME – “/usr/lib/jvm/java-11-openjdk-11.0.7.10-4.amzn2.0.1.x86_64”

Click on Apply

2. Configure Git on Jenkins

Goto Manage Jenkins -> Global Tool Configuration -> JDK Installations -> Add Git -> Git

Uncheck the option “Install Automatically”

Add a Name – “Default”

Run the following command in AWS EC2 Server to find the Git path:

git --exec-path

Add the Git path in Path to Git executable – “/usr/libexec/git-core/git”

Click on Apply

3. Configure Maven on Jenkins

Goto Manage Jenkins -> Global Tool Configuration -> Maven Installations -> Add Maven

Uncheck the option “Install Automatically”

Add a Name – “Default”

Run the following command in AWS EC2 Server to find the Maven path:

mvn -version

Add the Maven path in MAVEN_HOME – “/usr/share/apache-maven”

Click on Apply

4. Finally click on Save

Create Jenkins Job to Run Selenium Tests on AWS EC2 Linux Server

1. Click on New Item

2. Select the Freestyle project and Enter an item name

3. Enter some Description for the Job

4. Select “Git” in the Source Code Management and enter the following Repository URL: https://github.com/patebija/Selenium-Course.git

5. Add Build Step -> Invoke Top level Maven Targets

6. Enter the following maven command in Goals: clean install

7. Click on Save

8. Go to Dashboard and click on Build Now.

9. View the Console Output to see the Selenium Tests running on Chrome Headless Browser in AWS EC2 Linux Server.

Below is a detailed video which explains the below steps:

 

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!