How to start a simple Selenium Project Part 1 — Implementation

Denise Andron
6 min readDec 16, 2023

--

Hello, I’m Denise, and my venture into QA testing began more than 6 years ago during my college days. It wasn’t until 3 years ago that I discovered my genuine passion lies in automating websites. Navigating through my journey, I often faced challenges when initiating new projects — questions about the necessary tools and the ideal folder structure always lingered.

Now, I’m excited to guide you through a swift and seamless project startup.

This is Part 1 of our implementation!

Automation Framework (Hybrid) for Luma Website (softwaretestingboard.com)

Phase 1 : Implementation

Create maven project, in Eclipse you already have the option to create a Maven Project, but as a quick recap, you can do so by going to File -> New -> Maven Project

After we have created our maven project, we first create our folder structure, will look like this:

In the src/test/java folder, we keep things neat and tidy. We have specific places for everything — pageObjects for our pages, testCases for our tests, testData for our data files, utilities for handy tools, Drivers for our drivers, Screenshots for reports, and Configurations for important settings. Simple and organized!

Next step in our implementation is setting up our pom.xml file, we can download our dependencies from Maven Repository: Search/Browse/Explore (mvnrepository.com)

We will need the following: Selenium, TestNG, Apache POI, Extent Report, Sikuli ( for API )

( Clicking save after adding the dependencies, will automatically install them) you can also do a clean -> install do be safe

Next, we add the driver into our Drivers folder, you can download it from :

Chrome for Testing availability (googlechromelabs.github.io) check out this guide on how to do it: https://www.browserstack.com/guide/run-selenium-tests-using-selenium-chromedriver

We will now start building our test case, and we start by creating our LoginPage.java page object :

Meanwhile I moved to IntelliJ from Eclipse but kept almost the same folder structure. I createad a constructor LoginPage where I initiate the driver, local driver and remote driver, then initiate the Page Factory that we will be using for our locators.

Add your site locators and create basic flows like this:

We just want to create a simple yet robust framework that we can build upon later on.

Before delving into test details, establish a “Base Class” to store common methods like setup and teardown, ensuring efficient code organization.

Leverage Java Inheritance: Tap into Java’s inheritance concept, allowing your test case class to inherit essential methods from the Base Class.

Efficiency through Inheritance: By inheriting setup and teardown, each test case gains shared functionalities without redundant code, making your test suite efficient and easy to maintain.

In summary, this setup method is responsible for configuring the ChromeDriver path and initializing the WebDriver instance, ensuring it runs once before any tests in the test class.

Create a simple test case, making sure that our configuration that we did so far, works as expected, can look like this:

We will later optimize this and add the credentials to a data file.

Before we run our tests, lets add our reporting tool, Log4j, to do this we will get the repository ( website linked above) for Apache Log4j and add it to our POM file

To implement it to our test, we will add a new file in our project directory called log4j.properties

Since we will use this for all of our tests, we will set it up into our BaseClass, like this:

In simpler terms, you’re setting up a logger named “YourProjectName” and configuring its behavior using settings from the file called “Log4j.properties.” This helps you manage and understand what your program is doing by keeping track of certain events or messages.

In our test, we will add log messages for all of our steps, and it will look like this:

If we want, we can implement the logger into our methods in the pageObjects, but for now we are doing it in the test.

Running the test:

A new folder called logs, containing our reports for this run was created.

Lets improve our code even more by adding all of our common variables to a properties files, like our URL and so on, the file will be called config.properties and will be placed inside the folder that we created earlier called ‘Configurations’. Then, we have to create an utility class, similar like a middle man to actually get the values we define in the config.properties so that our BaseClass can use them.

Here you can define also the path of the browsers drivers, I will be using only Chrome for my tests but I will show you how to implement multiple browsers, for now Ill leave those empty.

We will create our utility file under com.Luma.utilities package

I left a few comments to explain each line of code, but shortly, an object, props, is created to handle properties from the configuration file.

  • The constructor initializes the configuration file’s path (./Configuration/config.properties).
  • It utilizes FileInputStream to open the file in read mode.
  • The properties are loaded into the props object at runtime using props.load(fis).

In essence, this class sets up a mechanism to read configuration properties from the specified file during its instantiation.

We will start creating methods for each key-value pair from our config.properties to read them, like this:

For now, I created one for our app URL and one for our chrome URL, similarly you should create for the other browsers you are using.

Calling the methods in our BaseClass like this:

This code snippet creates an instance of the ReadConfig class named readconfig and then initializes a String variable baseURL by retrieving the application URL from the readconfig object.

Next step into our implementation is making sure that we can run our tests in any browser.

Next in Part 2 ->

--

--