Skip to content

mokhtarhalim/salesforce-selenium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce Selenium Automation Framework (Java + TestNG)

Overview

This project is a UI automation framework for Salesforce Lightning built using:

  • Java
  • Selenium WebDriver
  • TestNG
  • Maven
  • Page Object Model (POM) design pattern

The framework automates key Salesforce scenarios such as:

  • Login
  • Navigation through App Launcher
  • Account management (Create / Update / Delete)

This project follows best practices for maintainability, reusability, and scalability.


Project Structure

salesforce-selenium
│── pom.xml
│── README.md
└── src
    └── test
        └── java
            └── com.qa.salesforce
                ├── base
                │   └── BaseTest.java
                ├── pages
                │   ├── LoginPage.java
                │   ├── HomePage.java
                │   ├── AppLauncherPage.java
                │   └── AccountsPage.java
                ├── flows
                │   └── NavigationFlow.java
                ├── tests
                │   ├── AccountTest.java
                │   ├── AccountUpdateTest.java
                │   └── AccountDeleteTest.java
                └── utils
                    └── WaitUtils.java

Framework Architecture

The framework follows the Page Object Model (POM):

Layers

1. Base Layer

BaseTest.java

  • Initializes WebDriver
  • Opens browser
  • Performs Salesforce login
  • Handles setup and teardown (@BeforeMethod, @AfterMethod)
  • All test classes extend this class

2. Page Layer (pages/)

Each class represents a Salesforce page and contains:

  • Locators
  • Actions (click, type, search, etc.)
  • No test logic

Classes:

  • LoginPage – Handles login actions
  • HomePage – Home screen operations
  • AppLauncherPage – App Launcher interactions
  • AccountsPage – Create, search, update, and delete Accounts

3. Flow Layer (flows/)

NavigationFlow.java

Purpose:

  • Contains reusable business navigation steps

  • Example:

    • Open App Launcher
    • Search for "Accounts"
    • Navigate to Accounts page

This avoids duplicating navigation logic across tests.


4. Test Layer (tests/)

Contains TestNG test classes.

Each class focuses on one functional area:

Class Purpose
AccountTest Create a new Account
AccountUpdateTest Update an existing Account
AccountDeleteTest Delete an Account

Best Practice:

  • Tests are independent
  • Each test uses reusable Page and Flow methods
  • Assertions validate expected behavior

5. Utilities Layer (utils/)

WaitUtils.java

  • Explicit wait methods
  • Improves stability and avoids Thread.sleep()
  • Used across page classes

ConfigReader.java

  • Reads values from config.properties
  • Provides them to the framework using getter methods
  • This allows tests to run without modifying code when environment values change.

6. Resources Layer (tests/resources/)

config.properties

  • This file stores environment specific data such as : URL, username, password, browser ...
  • Purpose: # Avoid hardcoding credentials or URLs in the code # Easily switch environments (Dev / QA / UAT) # Improve security and maintainability

Test Execution

Run all tests

mvn test

Maven will:

  • Compile the project
  • Execute all TestNG tests
  • Run them using Surefire plugin

Note: Test execution order is not guaranteed unless a TestNG suite is used.


Dependencies

Defined in pom.xml:

  • Selenium Java
  • TestNG
  • Maven Compiler Plugin

To download dependencies:

mvn clean install

Design Principles Used

  • Page Object Model (POM)
  • Separation of concerns
  • Reusable navigation flows
  • Explicit waits (no hard sleeps)
  • Test independence
  • Maven project structure

Example Execution Flow

For Account creation:

Test Class → BaseTest (browser + login) → NavigationFlow (go to Accounts) → AccountsPage (create account) → Test Assertion


Future Enhancements (Planned)

  • TestNG XML suites (ordered execution)
  • Data-driven testing (Excel/JSON)
  • Screenshot on failure
  • Reporting (Extent Reports)
  • CI/CD integration (GitHub Actions)

Author / QA Notes

This framework is designed as a scalable starting point for Salesforce UI automation and can be extended to automate other Salesforce objects such as:

  • Contacts
  • Opportunities
  • Leads

The structure allows easy maintenance and collaboration within a QA team.


Environment Setup (Prerequisites)

Before running the project, make sure the following tools are installed on your machine.

1. Install Java JDK

This project requires Java 17 (or higher).

Check if Java is installed:

java -version

If not installed:

  1. Download JDK from:

  2. Install the JDK.

  3. Set environment variables:

Windows

  • Create a variable: JAVA_HOME → path to your JDK folder
  • Add %JAVA_HOME%\bin to your Path

Verify installation:

javac -version

2. Install Maven

Maven is used to manage dependencies and run the tests.

Check installation:

mvn -version

If Maven is not installed:

  1. Download Maven: https://maven.apache.org/download.cgi

  2. Extract it (example: C:\apache-maven)

  3. Set environment variables:

Windows

  • Create MAVEN_HOME → Maven folder path
  • Add %MAVEN_HOME%\bin to Path

Verify:

mvn -version

3. Install Visual Studio Code (Recommended)

Download: https://code.visualstudio.com/

Install the following extensions:

  • Extension Pack for Java
  • TestNG for VS Code
  • Maven for Java

4. Get the Project

Clone the repository:

git clone <https://github.com/mokhtarhalim/salesforce-selenium >
cd salesforce-selenium

Or download the project and open the folder in VS Code.


5. Configure Test Environment

Update the file:

src/test/resources/config.properties

Example:

url=https://login.salesforce.com
username=your_username
password=your_password

This avoids hardcoding credentials inside the code and allows easy environment changes.


6. Install Project Dependencies

From the project root, run:

mvn clean install

This will:

  • Download Selenium dependencies
  • Download TestNG
  • Compile the project

7. Run the Tests

Execute:

mvn test

The framework will:

  1. Launch the browser
  2. Login to Salesforce
  3. Wait up to 60 seconds for manual MFA verification (if required)
  4. Execute all TestNG tests

Note: Test execution order is not guaranteed unless a TestNG suite (testng.xml) is used.


About

This is the extend the framework of Selenium using Salesforce

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors