Skip to content

UI‐Based Automated Testing Using Selenium and Java

Max Richard Jr edited this page Oct 19, 2023 · 6 revisions

Introduction and Purpose

This document describes how to obtain and configure an Automated Test Suite built for the LEAF Platform. The suite was developed using Java, Selenium, and TestNG. It will take approximately 2 hours to install and configure this Automated Test Suite.

Prerequisites

In order to execute the test suite, you will need to download and install:

  • The latest version of the Eclipse IDE for Java Developers from The Eclipse Foundation. The latest versions of the Java JDK and JRE are included in the install package and will automatically installed. If needed, the Java can be updated by navigating to Help -> Check for Updates. Ensure that the Java version is compliant with the VA Technical Reference Model (TRM).

  • You will also need to download and install Github – Use an account that is registered with the VA.

  • The latest version of the Selenium Client and Web Driver Bindings. Because this test suite is written in Java, select the Java version. Note that if you desire to work in another language, there is a separate install for most languages. Unzip the file.

  • The version of the Selenium Web Driver that corresponds to your current version of Chrome and unzip the file. To determine which version you need, open Chrome, goto Help on the top menu and select About Google Chrome. This driver will need to be updated whenever your Chrome version is updated.


Configuring Eclipse

There is no actual installer for Eclipse. Simply unzip the contents of the file you download. Note: If multiple developers will be utilizing/contributing to the test suite, ensure that file paths/folder names are identical on each machine used.

Within the unzipped contents, locate Eclipse.exe and execute the IDE.

  1. Once Eclipse is loaded, go to File -> New -> Java Project. Name the project Test-Automation-GFE.

  2. Once the Java Project is created, right click on the Project and go to Build Path -> Configure Build Path. On the top row of tabs, select ‘Libraries’.

  3. Install Selenium. On the right hand column of buttons, select ‘Add External Jars’.

    a. Navigate to the location where you unzipped the Selenium Client and Web Driver Bindings

    b. Select all .jar files, including those in subdirectories. You will need to install files in the first directory, select open, then ‘Add external Jars’ again to select additional files. Select the ‘Apply’ button within that tab.

  4. Once the above steps are completed, select ‘Add Library’ from the right hand column of buttons. If ‘TestNG’ is present, select it and select ‘Apply and Close.’ You can then skip to Step 5. If TestNG is not present, continue with these steps

    a. Select ‘Apply and Close’ to close the modal Build Path

    b. In the main Eclipse application, select Help -> Eclipse Marketplace. Type ‘TestNG’ in the search box. The Marketplace should automatically present the latest version of TestNG and install it.

    c. To add TestNG to the project, return to Configure Build Path by right clicking on the Project and go to Build Path -> Configure Build Path. On the top row of tabs, select ‘Libraries’.

    d. You should now see TestNG among the applications. Select it, and ‘Apply and Close’

  5. Create the folder/path C:\Selenium\Current_ChromeDriver. Within the Chromedriver zip file you downloaded, copy the extracted file ‘chromedriver.exe’ into the \Current_ChromeDriver folder.

  6. Add additional ‘views’ in Eclipse by selecting Window -> Show View from the top (horizontal) menu across the Eclipse application. You will want to chose Project Explorer, which allows you to see all files (vs project files only). By selecting Window -> Show View -> Other, you can type in ‘TestNG’ and ‘Git Repositories’ to get the views associated with those applications. Since you will not be committing to this repository, there is no need to select the Git Staging view.


Configure Git and Access Source Code

Using the Git Repository view which you enabled above, you will want to go to that view (usually located in the lower left-hand corner), and select the option, ‘Clone a Git repository and and add the clone to the view’.

Follow these steps:

In GitHub

  • Go to the Test-Automation-GFE GitHub site. You will need to use a VA approved account to access content. Select the Test-Automation-GFE branch.

  • On the main repository page, there is a green button with the label ‘Code’. Select this button and copy the address from the https tab.

In Eclipse

  • In the Eclipse ‘Git’ view – choose ‘Clone a Git repository and and add the clone to the view.

  • Select Repository Source – Choose ‘Clone URI’ and select Next

  • Source Git repositories – paste in the address that you copied from GitHub into the URI field. All other information should then populate, although if you have not saved your credentials to the Eclipse secure store, you will have to enter your credentials. Select Next.

  • Branch Selection – By default, all LEAF branches will be selected. If you desire only the code for the automated test suite, chose only the ‘Test-Automation-GFE’ branch. Select Next.

  • Local Destination – Choose the location where you would like your local repository to reside. Be sure to set the Initial Branch to Test-Automation-GFE. Select Finish. Your repository will then be cloned. This may take several minutes depending on the number of branches you selected.

Once the clone process has finished:

  1. Goto the location of your cloned repository and navigate to the src folder within ..\LEAF\test\Test-Automation-GFE\src. Copy all files and folders
  2. Navigate to the \src folder within the Java project you created in the steps above. Paste all files and folders into the \src folder.
  3. In Eclipse, select the project name at the top of the tree view on the left-hand side. Right click and select ‘Refresh’. Alternatively, the F5 key will also refresh your Java project.

Share the Project

In Eclipse, select the project name at the top of the tree view on the left-hand side. Right click and go to Team -> Share Project. A dialogue box titled, 'Configure Git Repository' will open. Follow these steps:

  1. To the right of the Repository field there is a dropdown arrow. Click the arrow and your local repository will be displayed.
  2. In the ‘Path within Repository' field, enter ‘test’ as that is the folder that Test-Automation-GFE resides. Use the browse button to the right of this field to ensure you’ve selected the correct location within your local repository
  3. In the grid view below, ensure that both the Current Location and Target Location are correct. If an error displays, you may have to delete the Test-Automation-GFE within your local repository. Don’t worry, your files are still stored in the location of your Java project.
  4. Select ‘Finish’ and your project will now be synchronized with GitHub, which will allow you to pull down changes.

PLEASE DO NOT COMMIT TO THE REPOSITORY as this is the actual test bed for the LEAF project.