SDET Unicorns

Selenide Project and Test Setup

Table of Content

In this post, we will look at how to setup Selenide project in our machine and also how to setup our first test. One of the best parts about using Selenide is that you can get start with writing your first test in under 10 mins. Let’s take a look at that –

Pre-requisites:

  • Java Installed
  • Any IDE of your preference: I will be using IntelliJ for this series

Check out the video below to learn how to Setup Selenide Project and Test –


Selenide Project Setup

To get started with Selenide, we will first create a new Maven project in the IDE. Once the project is created, we will need to do the following steps –

Add Dependencies to POM.xml

  • Selenide:
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>6.5.0</version>
<scope>test</scope>
</dependency>
  • TestNG: testing framework
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>

That’s all you need in terms of setting up project. Rest, Selenide will take care of on its own.


Test Setup

Now, let’s create our first Selenide Test. To do that, simply create a new Java test file and add in the following code –

import com.codeborne.selenide.WebDriverRunner;
import org.testng.annotations.Test;

import static com.codeborne.selenide.Selenide.*;
import static org.testng.Assert.*;

public class HomeTest {
    @Test
    public void testPageUrlAndTitle() {
        // Open page url
        open("https://practice.automationbro.com/");
            
        // Assert the url matches 
        String url = WebDriverRunner.url();
        assertEquals(url, "https://practice.automationbro.com/");
        
        // Assert the title matches
        String title = title();
        assertEquals(title, "Practice E-Commerce Site – Automation Bro");
    }
}

In the test above, we are doing the following steps –

  • Importing all the necessary dependencies
  • Created a test method to verify the page url and the title
  • Open the page url using the in-built open method
  • Then assert the url and the title of the page

Run Selenide Test

To execute the test, you can run it via the maven test command – mvn test. Selenide will do the following –

  • Spin-up chromedriver
  • Start the test session
  • Execute the test
  • Stop the test session
  • Close the browser

You do not have to worry about setting up your driver or handling the opening/closing of the driver. All of this gets taken care of by Selenide and you can focus on writing beautiful tests.

Screen Shot 2022 06 26 at 2.20.36 PM

Hope you guys liked this article!

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

7 Principles of Software Testing

7 Principles of Software Testing with Examples

Software testing plays a crucial role in the software development life cycle as it helps ensure the quality, reliability, and performance of the final product. Software testing is not just about finding defects; it also provides valuable insights into the overall quality of the software. By conducting effective software testing, it shows how well the application behaves in different scenarios and whether it meets user expectations.

Read More »
Differences Between CI/CD and DevOps

Key Differences Between CI/CD and DevOps

Software development is far from a simple journey that involves merely executing code and launching applications. It often presents challenges, as it’s rare to get everything right from the start. Each time you implement new or frequent code changes, you inadvertently introduce potential issues that can be time-consuming to resolve. This complexity necessitates a structured approach to ensure smooth production.

Read More »