Git is an essential and popular system for version control. Suppose your Katalon Studio automation project involves several or more members. In that case, you should use Git or another source control system for managing change and configuration on your test project. A Git repository can be shared across multiple team members to help improve the team's collaboration and productivity.
Below are several benefits of using Git for your Katalon Studio projects:
- Git allows undoing mistakes. The undo ability gives project teams the courage to try out ideas and concepts without worrying about the risk of breaking stuff and, thus, fosters a culture of innovation.
- Git makes the team progress clearer:
- A commit in Git refers to a change in automation scripts that a team member makes, indicating the progress of tasks.
- Git supports comparing versions of code to show differences between commits. It is useful to review a commit before it officially becomes final.
- Git supports working offline. Being to work offline makes your team more fail-safe. Each member can perform everything on his/her computer, independent from possible infrastructure downtime.
- Never losing data ever again. As daily work can be committed to the remote Git server, every team member working on a project has a full-fledged copy on his/her machine, including the project's complete change history.
- If any backup breaks down, restore it using any team member's local repository or Git repository.
About Git Integration
The Git integration supported in Katalon Studio is based on EGit. You can refer to http://wiki.eclipse.org/EGit/User_Guide for a detailed user guide regarding EGit. A typical workflow of Git integration with Katalon Studio is depicted in the following diagram:
You can integrate Katalon Studio with Git and its cloud-hosted services, including:
- Microsoft Azure DevOps
Configure Git Integration
Enable Git Integration: To access all Git features, you need to enable Git Integration first. The option is available in the following settings: Katalon Studio > Preferences > Katalon > Git. Once enabled, you can start using Git at Katalon Studio's main toolbar.
Now, the Git integration feature should be enabled. We are ready to use Git from Katalon Studio.
Advanced configurations are available at Katalon Studio> Preferences > Team > Git in case you want specific settings.
Clone a Katalon Studio project from a Git repository
After enabling Git Integration, you can clone an existing Git repository into a newly-created directory on the local machine.
On the main toolbar, select the Git icon > Clone Project.
The Source Git Repository dialog is displayed.
Connecting to Git with HTTPS
Enter all required information and click Next to let Katalon Studio get details about your repository.
- Repository URL: the remote URL to your Git repository in HTTPS protocol.
- Username: the username to access the Git repository.
- Password: the password to access the Git repository.
If you cannot access the repository after clicking Next, the connection may have issues with SSL verification. You can use the below command to bypass SSL verification (NOT recommended):
git config --global http.sslVerify false
Connecting to Git with SSH Keys
Starting from version 7.0.0, Katalon Studio supports connecting to Git with SSH Keys.
- Generating a public/private rsa key pair with this command:
ssh-keygen -m PEM -t rsa -b 2048 -C "email@example.com"
Note: Katalon Studio only supports
- Enter file in which to save the key.
- Enter the SSH key passphrase and confirm it.
- Add your SSH key to the ssh-agent.
- Add a new SSH key to your Git account.
In the Source Git Repository dialog, enter a repository URL with SSH Protocol and click Next.
Enter the passphrase for the key generated above.
At the Branch Selection screen, you can choose which branches to be checked out as local branches. Click Next to continue.
At the Local Destination dialog, specify the local location for cloning as well as the initial branch.
- Directory: the local storage location you want to store your Git repository.
- Initial branch: all selected branches from the previous step are displayed here. Select the branch to be used initially from this list.
Click Finish when you are done. Katalon Studio automatically opens your cloned project.
To verify settings, go to Katalon Studio> Preferences > Team > Git > Configurations > Repository Settings. Ensure that the repository is selected correctly with the URL specified.
Publish a local non-Git project as a Git repository
Share Project is a step to enable Git configuration for your new Katalon Studio project.
On the main toolbar, select the Git icon > Share Project.
Folder .git and file .gitignore are created within the Katalon project.
.gitignoretells Git which files (or patterns) it should ignore. By default, .gitignore contains these files and patterns:
/bin /Libs .settings .classpath /.svn
The Commit option allows users to view all current changes and decide which changes to be stored in the local branch. Refer to this document for detailed Git documentation regarding Commit command.
On the main toolbar, select the Git icon > Commit.
The Git Staging tab is displayed for configuration.
Field Description Unstaged Changes Changes which have been made. Staged Changes Selected changes from Unstaged Changes. These changes are committed.
From the Unstaged Changes list, select the changes to be committed, then right-click on them and select Add To Index. Selected changes are added to the Staged Changes list.
Enter your comments into the Commit Message, then click on Commit to store your staged changes into the local branch.
On the main toolbar, select the Git icon > Manage Branches > New Branch.
The Create Branch dialog is displayed.Where:
Field Description Source
Select either remote or local branch, which is your source branch.
Branch name The name to be used for the new branch. Checkout new branch Option to let Katalon Studio checkout that branch after created.
Click Finish to create a new branch.
The Checkout Branch option allows you to switch from one branch to another.
On the main toolbar, select the Git icon > Manage Branches > Checkout Branch.
The Select Source dialog is displayed. Select the local branch you want to check out to be the current branch. The branch with an √ icon is your current local branch.
Click OK to finish checking out to the new local branch.
On the main toolbar, select the Git icon > Manage Branches > Delete Branch.
In this dialog, both local and remote branches are displayed. Select a branch to be deleted, then click OK.
Retrieve all information about changes that have occurred in remote branches. Refer to this document for detailed Git documentation regarding the Fetch command.
On the main toolbar, select the Git icon > Fetch.
It automatically fetches remote branches, tags, and remote changes.
Select History on the main toolbar.
Details regarding all the branches and tags you've just fetched are displayed.
Incorporate changes from a remote repository into the current branch. Refer to this document for detailed Git documentation regarding Pull command.
On the main toolbar, select the Git icon > Pull.
In the Pull dialog, select the remote branch to be pulled into your local branch. Click Finish.
The Pull Result dialog is displayed with all data about pulling requests on the selected branch.
Update the remote branch using the local branch. Refer to https://git-scm.com/docs/git-push for detailed Git documentation regarding Push command.
Before doing any push, you have to commit your changes first.
From the main toolbar, select the Git icon > Push.
The Push to Branch dialog is displayed. Choose from the Remote branch list which branch to be updated (All remote branches in your Git repository are listed here).
Click Next after finished selecting your remote branch.
If you enter a different name besides the listed branches, a new remote branch with that name is created accordingly.
The Push Confirmation Dialog is displayed with details regarding your commit.
Click on Finish to push your commits to the remote repository.
Resolve Git conflicts using Katalon Studio
Why do we have Git conflicts?
In a source control system like Git, conflicts occur when two or more people make changes to the same file concurrently. The conflicts may appear at a member's local repository or Git remote repository.
To avoid conflicts, the team must collaborate following several Git practices. For example, before pushing new source code to the Git remote repository, one must remember to fetch the latest version from Git remote repository, resolve any conflicts, and merge the code with the local version.
The chart below demonstrates how conflicts may occur when Tom and Emma are working on the same project. The conflicts occur when Tom and Emma try to push new code to the Git remote repository without updating the changes from each other.
Resolve Git conflicts using Katalon Studio
Tom and Emma are working on the same test case in a test project. Emma added a new comment ("EMMA ADDED THIS COMMENT"), then committed and pushed the change to the Git remote repository.
At almost the same time, Tom also added a new comment ("TOM ADDED THIS COMMENT"), then committed and tried to push to the Git remote repository.
Unfortunately, since Emma had pushed the code before Tom, so the version of code in Git was different from the version of code in Tom's local repository, and therefore, Git rejected Tom's push action.
Question: What should Tom do to push its change to the Git remote control?
First, Tom has to pull the code from the Git remote repository to his local machine.
Obviously, Tom will see a message about the conflict:
In the Script mode of the test case TC2_Verify Successful Appointment in Tom's Katalon Studio project, there are errors with indicators such as "<<<<<<<" (convention from Git). Let's look at the script more carefully:
Recall that the comments were added by Tom and Emma, and the conflict is now on Tom's Katalon Studio project. Everything within "<<<<<<< HEAD" and "=======" is the change from Tom. And, everything within "=======" and ">>>>>>> branch 'master'…" comes from Emma, which is currently in the Git remote repository.
Now Tom has to decide which change is correct, or both are correct or wrong. Tom has to replace these lines of code with the correct ones. For example, "THIS IS THE CORRECT COMMENT":
After resolving the conflict, Tom is now able to commit and push the change to the Git remote repository.
In order to minimize the conflict in a team having more than one member, you should define a process from the very beginning so that all team members are on the same page when using Git.
Below are some suggestions for good practices:
- Commit often: do not wait until a huge amount of scripts created to commit and push to the Git remote repository. The smaller the set of scripts is pushed, the easier you resolve the conflict.
- Pull changes from the Git remote repository before working on new scripts and before committing. Each member works on each feature at a time.