SVN Tutorial: Source Code Management Using Subversion

Introduction to Source Code Management Using Subversion (SVN):

Welcome to the Subversion(SVN) series. This informative SVN Tutorial explains the basics of the software versioning concept and how SVN can be useful for the development team.

What Is SVN?

SVN is a simple and open-source license Software Configuration Management (SCM) tool that can be used in all the phases of Software Projects.

  • SVN is a Subversion control tool that helps us to maintain all the project artifacts in a script repository.
  • It’s a free/open-source tool that helps us to manage software versioning and revision control system.
  • It is easy to understand and works faster when compared to the other tools (For Example, GIT, mercurial).

Read this first tutorial of the series about basics of Subversion thoroughly before you proceed to the next one.

Source Code Management Using Subversion

List Of Tutorials In This Subversion Series:

Tutorial #1: SVN Tutorial: Source Code Management Using Subversion
Tutorial #2: How To Setup SVN Repository And Install Tortoise SVN Client
Tutorial #3: Tortoise SVN Tutorial: Revisions In Code Repository
Tutorial #4: How To Delete Content From SVN Repository


Overview Of Tutorials In Subversion Series:

Tutorial NumberWhat You will learn
Tutorial_#1:SVN Tutorial: Source Code Management Using Subversion
This informative SVN Tutorial will explain the basics of software versioning concept and how SVN can be useful for the entire team.
Tutorial_#2:How To Setup SVN Repository And Install Tortoise SVN Client
You will learn how to set up a free server repository and a free Tortoise SVN client UI to import and export code to/from the repository from this tutorial.
Tutorial_#3:Tortoise SVN Tutorial: Revisions In Code Repository
This tutorial will brief you on how to use Tortoise SVN client to check-out and check-in the code from/to repository with simple practical examples for your easy understanding.
Tutorial_#4:How To Delete Content From SVN Repository
This SVN tutorial will teach you how to remove the code content from the repository. SVN helps you to version your project.

Basic Terminologies

Before we get into the details, let’s understand the basic terminologies that we will be using in this tutorial.

Repository: It is a central place or repository where all our project artifacts like (Design, Source code, Documentation, test cases) are stored. Individual users can locally check out the files in their local machine and can work on it.

As it maintains all the history information of the particular artifact, the users can go back and look into the log to see “Who & When & Why” has changed.

SVN Checkout: It is a process of taking the project artifacts from the central repository to the local machine. Users can do modifications and can save changes locally.

Commit: It is a process of saving the changes from local machines to the central repository. During the commit, we should provide meaningful commit messages so that the other users can easily understand.

Now we understood the basic terminologies of SVN. We will see an example of how it works in the day to day business.

SVN Workflow

Consider a scenario, where the Team lead has created a Framework skeleton that contains Automation scripts. Now, he is trying to upload it in a Centralized location called ‘Automation Script Repository’.

The members of the team are ready to check out the Automation skeleton scripts from the repository to their local machines. Once, they are done with the scripts changes, they can go back and commit it to the centralized repository.

SVN Workflow

Download SVN

Step #1: Visit Google’s website and type ‘Download SVN’.
Step #2: Click on the Link ‘Download Tortoise SVN’ from the website, Tortoise SVN
Step #3: Choose the link, Tortoise SVN 1.9.6 – 64 bit/32 bit depending upon the OS that you have in your system.

Download Tortoise SVN

Step #4: Upon clicking the respective link, Download starts and we get the .msi setup file at the bottom of our screen.

Download window

get .msi setup file

Step #5: Click the .msi file and run the setup wizard by clicking the Next button.

Run the setup wizard

Tortoise SVN Installation is done successfully without any errors.

Plugin To Work Tortoise SVN Through Java Eclipse

To support our Subversion in the Eclipse IDE, we should install the plugin called Eclipse Team provider or Subclipse Plugin.

Step #1: Go to the Help menu from the Eclipse IDE environment and Click ‘Eclipse Marketplace’.

Eclipse Marketplace

Step #2: Type Subclipse in the Find text box and click the Go button.

Choose the first link, Subclipse 4.2.3 and then click on the Install button.

Install Subclipse

Step #3: A dialog box as shown below will be displayed. Click the Confirm button to continue with the installation process.

Confirm selected feature

Step #4: Accept the Subclipse software license and click on the Finish button.

Accept the Subclipse software license

Accept the license

Subclipse Plugin is successfully added to the Eclipse IDE.

Framework Creation In Java Eclipse

A sample framework design called ‘Hybrid_Framework’ using the Page Object Model (POM) Java design pattern is created. A Maven project is created with all the source codes written in the src/test/java folder.

Two packages with their names com.qspiders.Pages and com.qspiders.Tests are created.

Here we are trying to perform the login operation. Once the login is successful, it navigates to another page called ‘EnterTimeTrack’.

Framework Creation in Java Eclipse

  • All the actions and verifications are performed under the com.qspiders.Pages package.

com.qspiders.Pages package

  • Object creation of that particular page and script execution is performed under the com.qspiders.Tests package

Object creation of the particular page

Creation Of Repository

Step #1: For repository creation, go to the folder where the project is saved and Right-click Tortoise SVN and choose ‘Create repository here’ option.

Create repository here option

Step #2: Repository creation is done successfully on the specified Path.

Repository creation successful

Step #3: We can see the icon change in framework (POM_Framework) creation.

Icon change in framework (POM_Framework)

Pushing The Framework Into Repository

Step #1: Right-click on Project and choose Team -> Share Project.

Team-Share Project

Step #2: Choose SVN and click Next.

Select a Repository type

Step #3: Select ‘Create a new repository location’ and click Next.

Create a new repository location

Step #4: Give the URL that you have given for repository creation and click the Finish button.

URL for repository creation

Step #5: We have successfully added our framework into the repository folder.

Framework added into the repository folder

SVN Checkout

We are trying to checkout the project folder POM_Framework by following the below steps.

Step #1: Right-click outside the folder path and choose SVN Checkout.

Select SVN Checkout.

Step #2: Choose the repository path and click OK.

Repository path

Step #3: The project folder is successfully checked out in the mentioned path and it automatically sets the revision number.

Checkout finished

Commit: The below piece of code has been added in the LoginTests.java file and we are trying to commit it in the repository.

Source Code:

Package com.qspider.Tests;

Public class LoginTests {

Public static void main(String args[])

{

WebDriver driver = new FirefoxDriver();

driver.get("file:///E:/Uma/Selenium%20Programs/mypage.html");

WebElement txtFirstName = driver.findElement(By.id("txtfirstname"));
txtFirstName.sendKeys("Uma");

 WebElement txtLastName = driver.findElement(By.name("txtLastname"));
txtLastName.sendKeys("Srinivasan");

WebElement txtPassword = driver.findElement(By.className("pi"));
txtPassword.sendKeys("UmaPassword");

driver.findElement(By.tagName("a")).click();
driver.navigate().back()

}

}

Step #1: Right-Click the project and select Team -> Commit.

select Team -> Commit option

Step #2: A dialog box as shown below will be displayed, just choose the file that has been changed by the user. Enter the comments in the text box, ‘What we added/changed/Deleted’.

Enter the comments in the text box

Step #3: Now the file/folder is successfully checking in to the repository.

successfully checking

Why Do You Need SVN?

Suppose you are in the process of developing a Selenium automation project. Let us say there are three team members working on this project: Tester A, Tester B, Tester C.

Now assume, there are 15 automation test scripts that need to be written. So these three teammates decide to divide five scripts each amongst themselves and start automating them. Now, in the end, they will all merge their code and the final code will be built. The Blue circular shape in the figures below represents the final merged code.

If ‘Tester A’ decides to make some correction in his piece of code, then he will have to get the whole merged code into his local workspace so that he can correct it as shown in the below figure. Workspace means a simple Selenium project.

Final merged code

Similarly ‘Tester B’ will also have to get the whole code into his workspace if he wants to make any changes to his/her test cases.

Final merged code of B

But the problem that will arise is that each and everyone will now have a different version of the workspace. The changes that ‘Tester A’ has done in his workspace, will not be present in the workspace that ‘Tester B’ has as shown below. There will be no synchronization of workspaces between the team members.

Tester B not in sync with changes made by Tester A

If a new team member joins and he wants to set up his local workspace, then there will be conflict about which Tester should give him his workspace? Thus, there will be confusion. Here, we are talking about three testers, what if you are working on a big automation project comprising of many testers?

Hence, to resolve these code synchronization issues and to ensure that everyone in the team is on the same page, we use Subversion SVN.

There are many other tools in the market that help in source code management. Few are free (open source) like CVS (Concurrent Versioning System), RCS (Revision Control System), Git. While a few are licensed like Rational ClearCase.

What Is The SVN Repository And What Does It Do?

The SVN repository provides a management system through which you can control the versions of your project and/or software.

So, you need to have a centralized server repository (server can be Windows, Unix, Linux based, etc). We will be putting our final merged code onto this server.

Now suppose the ’Tester A’ checks out the code from the centralized server which is known as the repository. After making the desired changes to his code, he checks-in back to the updated code into the repository. Now ‘Tester B’, when he checks out the code, gets the latest code from the repository.

Similarly, everybody does their respective changes and then update (check-in) the code in the repository.

Thus everyone is in sync and is on the same page.

Explaining Repository

Conclusion

This tutorial helped us understand the basic concepts of SVN. We started with the basic terminologies of SVN and then moved to Installation, Plugin Configuration, Framework design, and repository creation. We have also seen what a repository is and what does it do.

Finally, we learned how to push the framework into the repository & file checkout and commit.

In the upcoming tutorial, we will see how to set up a free repository of our own.

NEXT Tutorial