What is Github?
GitHub is a web-based version-control platform that uses Git, designed to enhance collaboration among software developers. As a powerful tool, GitHub allows multiple users to make separate changes to a project simultaneously, making it ideal for team environments.This open-source version control software maintains both remote and local copies of your project, enabling you to publish, share, and update the project with your team members easily. When working with Selenium software testing, this capability ensures that test scripts and updates are seamlessly accessible to all team members, supporting efficient collaboration and version control in test automation projects.
When working on test automation, GitHub integration with Selenium becomes highly valuable, as it allows testers to manage their Selenium scripts collaboratively, track changes efficiently, and ensure that everyone on the team has access to the latest updates and improvements in the testing framework.
Advantages of Git Hub for Selenium.
- Using Github in a central repository we can store our code from where all team members can use, share, modify the code with each other.
- You can take a backup of your project in case if your code remove from the local system
- We can perform actions like code pull, commit, push, etc.
- Github can easily track every change made by team members
- By using Eclipse we can integrate Github with selenium so that we can push, pull, or commit changes from Git.
- You can easily access all the committed code at any time from anywhere in the world
- When multiple people are working on the same project they can update the project details and information to other team members simultaneously.
Prerequisite required for Selenium and Github Integration
The below components are to be installed before we start Selenium and Github integration.
- Tomcat Installation
- Jenkins Installation
- Maven Installation
How to Install Git?
We follow the below steps to install Git
Step 1: Open the Browser and navigate to the URL- https://git-scm.com/
Step 2: Click on the Download button for the latest stable release as shown in the below image.
Step 3: Click on Downloads for windows to begin the installation
Step 4: To start the installation process double-click on the downloaded setup file.
Step 5: Click on the Next button
Step 6: Select the location where you want to install Git. Click on the Next button.
Step 7: Select the following components which you want to install as shown in the below image. Click on the Next button.
Step 8: On this wizard, you find an option to create a shortcut. By default, the Start Menu folder is pre-selected. Give the location if you want to change, else leave it the setting default. Click on the Next button.
Step 9: In this step,
- Select the second option “Use Git from the Windows Command Prompt” by selecting this we will be able to run Git from the command line and
- Click on the next.
Step 10:
- Select the checkbox “Use OpenSSH”, which help us to execute the command from the command prompt.
- Click on the Next button.
Step 11: In this step,
- Select the checkbox “Checkout windows-style, commit Unix-style line ending” and Click on the Next button.
Step 12: In this step,
- Check the option “Use MinTTY is the default terminal of MSys2” for Git Bash
- Click on the Next button
Step 13: In this step,
- Check the option “Default(fast-forward or merge)
- Click on the Next button
Step 14: Choose the option Git Credential Manager and click on the Next button
Step 15: In this step,
- Check the option “Enable file system caching
- Click on the Next button
Step 16: Click on the Install button
Note: Once the installation is completed, we need to verify whether git was executed successfully or not. To verify that, open the Command Prompt and type “Git” and hit the “Enter” key. If the below screen displayed means then it means that it is installed successfully.
Set Up Eclipse with Git Plugin
Step 1: Launch the Eclipse and click Help ->Click on install new software
Step 2: The below screen will be displayed and click on Add button.
Step 3:
- Type the name “EGIT” and
- Enter the location https://download.eclipse.org/egit/updates/ then
- Click on the Add button.
Step 4: Click on the Select All and Click Next button
Step 5: Click on the Next and select the option ‘I accept the terms of the license agreement’ then click on the Finish button.
Restart the Eclipse.
Creating a Repository on GitHub
To create a repository on GitHub follow the below steps:
1. Navigate to the Url https://github.com/.
2. Sign-Up for git hub.
3. Sign-Up with valid credentials.
4. Click on the “Create Repository” as shown in the below image.
5. Enter the name of the repository in the “Repository name” text box.
6. Click on the “Create Repository” button.
Selenium Integration with GitHub using Eclipse IDE
Below steps are involved in the Github Integration with Selenium Using Eclipse IDE
Step 1: Launch the eclipse and then navigate to the project
Step 2: Right-click on the project and select “Team” then
Step 3: Click on the Share Project
Step 4: Select the Repository. If data is not displayed in the drop-down, then click on the Create.
Once we click on the Finish button, we can notice the following change in the project structure of your Selenium project.
Step 5: Right-click on the project and Navigate to Team ->Commit.
Step 6: Right-click on the Selenium project and navigate to Team and click on Add to Index.
Step 7: Enter the commit message and click on the Commit button.
This will add all your Test Cases files to staged changes.
Step 8: In the Eclipse Open Git repository tab.
Note: Follow the below steps if the Git repository tab does not open by default
a) Navigate to Windows Tab in Eclipse -> Click on Show view -> Click Other.
b) Expand the Git folder and select, Git repositories, and Git Staging, and click on the Open button.
Step 9: Right-click on the remote and navigate to Create Remote under the Git Repository tab.
Step 10: You can see a new pop-up window got open, and enter the remote name. Leave the other settings as same and click on the Create button.
Step 11: Another pop-up window will got open and click on the Change button
Step 12: Provide the URL and your login credentials of the GitHub account as shown in the below image, and click on the Finish button.
Step 13: Once the configuration process is finished, select the branch to commit changes. Click on the Advanced button as shown in the below image.
Step 14: Select your branch and click on the Add Spec button.
Step 15: Click on the Finish button and you will find a folder with the name you provided under Remote.
Step 16: Right-click on the URL of the red arrow, and click on Push.
Step 17: Thus, all the changes were made and your Test Cases will get committed to the repository.
Adding a Maven Project to GitHub Repository
Step 1: Open eclipse and click on File -> New -> Project -> Maven Project
Step 2: Check the option “Create a simple project” and click on the “Next” button.
Step 3: Enter Group Id and Artifact Id as “MyProject” and click on the “Finish” button.
Step 4: Create a new package “mySeleniumPackage” under src/test/java of our Maven project and click on the “Finish” button.
Step 5: Under mySeleniumPackage create a new class “OpenFacebook” and enable main() method.
Step 6: Update the pom.xml file with Selenium and TestNG dependencies
<project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion> <groupId>MyProject</groupId> <artifactId>MyProject</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.1.0</version> </dependency> </dependencies> </project>
Step 7: Create a Selenium test to open Facebook home page and get the title of the webpage
package mySeleniumPackage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class OpenFacebook { @Test public void testcase() { WebDriver driver; System.setProperty("webdriver.gecko.driver", "C:\\drivers\\geckodriver.exe"); driver = new FirefoxDriver(); driver.get("https://www.facebook.com"); System.out.println(driver.getTitle()); driver.close(); } }
Step 8: Create an xml file named “test.xml” to run the created testcase. Enter your package name(mySeleniumPackage) and the class name(OpenFacebook)
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name = "Suite"> <test name="Test"> <classes> <class name="mySeleniumPackage.OpenFacebook"/> </classes> </test> </suite>
Step 9: Right-click on testng.xml file > Select Run As and Click on TestNG Suite
Creation of public GIT Repository?
Step 1: Login to www.github.com and click the ‘New” button to create a new repository
Step 2: Enter the name of your repository “SeleniumProject1”, select Public, and Click on the “Create repository”
Step 3: This will create a public repository in github.com and it can be accessed using the URL – https://github.com/xxxx/SeleniumProject1
Pushing your Selenium Project to GitHub
Step 1: Go to the Eclipse, select your project “MyProject” -> Right Click -> Team -> Share Project
Step 2: Configure Git repository to create a local repository of our Selenium project in our system. Select the check box “Use or create the repository in parent folder” and click “Create Repository” and click on the “Finish” button. This will create a .git file in the physical location of the project. In our case, the local repository is located at “C:\Users\hp\eclipse-workspace\MyProject.git”
Step 3: Right-click on the project -> Team -> Commit, to push the project to a remote repository.
Step 4: Eclipse will open a “Git Staging” window with 3 sections – Unstaged Changes, Staged Changes, and Commit Message.
Step 5: Unstaged Changes are the new files that need to get updated in the shared repository. We need to move Unstaged Changes to Staged Changes to add code to the shared repository. Once moved, give a “Commit message” and click on “Commit and Push”.
Step 6: Enter the shared repository details where we want to push the Selenium code. Also, give the Authentication credentials details to connect to the shared repository and push the code
Step 7: Click on the Push button
Step 8: Enter the credentials details once again to push
Step 9: We will get a confirmation message like below, once the project got pushed successfully to the remote repository.
Step 10: Go to the remote repository and refresh the page.
This is how we will create a Selenium project in eclipse and update it in the GIT repository.
Conclusion
- Github is a web-based version-control that uses Git.
- It is a collaboration platform for software developers to integrate the code.
- It is an open-source version control software so multiple users make separate changes to the project at the same time.
In conclusion, integrating GitHub with Selenium brings powerful version control and collaborative capabilities to your test automation projects. By managing your Selenium scripts on GitHub, you can easily track changes, collaborate with team members, and maintain up-to-date test code, all within a streamlined workflow.
This integration ultimately enhances productivity and ensures a more organized, efficient approach to software testing.
Call to Action
Ready to streamline your test automation with GitHub Integration in Selenium? Join H2K Infosys and learn how to seamlessly manage, collaborate, and version-control your Selenium projects. Our expert-led training will guide you through integrating GitHub with Selenium, ensuring your testing workflows are efficient and up-to-date.
Enroll now at H2K Infosys and elevate your automation skills to a professional level!