Setup Basic REST Assured Gradle Project In Eclipse IDE

HOME

In the previous tutorial, I have provided the Introduction of Rest Assured. In this tutorial, I will explain how to setup basic Rest Assured Gradle project in Eclipse IDE. Before going through this tutorial, it is recommended to go through previous tutorial to know about Rest Assured.

What is Gradle?

Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software. A build automation tool is used to automate the creation of applications. The building process includes compiling, linking, and packaging the code. The process becomes more consistent with the help of building automation tools.

Steps to setup Rest Assured Gradle Project in Eclipse

  1. Download and Install Java on the system
  2. Download and setup Eclipse IDE on the system
  3. Setup Gradle on System
  4. Create a new Gradle Project
  5. Add Rest-Assured dependencies to the project

Step 1- Download and Install Java

Rest-Assured needs Java to be installed on the system to run the tests. Check if Java is installed on your machine or not by using the below command on Command Prompt.

java -version

If Java is not installed, then click here to know How to install Java.

Step 2 – Download and setup Eclipse IDE on the system

The Eclipse IDE (integrated development environment) provides strong support for Java developers. If Eclipse IDE is already not present on your system, then click here to know How to install Eclipse.

Step 3 – Setup Gradle

To build a test framework, we need to add several dependencies to the project. This can be achieved by any build Tool. I have used Gradle Build Tool. Click here to know How to install Gradle.

Step 4 – Create a new Gradle Project

To know, in detail, how to create a Gradle project in Eclipse, refer to this link.

File ->New Project ->Gradle Project ->Next.

Provide projectname and location where you want to save the project on your system. Click the Finish Button.

Verify the Gradle Version and Gradle project structure name. Click the Finish Button.

Below is the structure of the new Gradle project.

Below is the structure and content of the build.gradle of the new project.

Step 5 – Add Rest-Assured dependencies to the project

Add Rest-Assured, JSON Schema Validator, and JUnit dependencies to the project.

    // Use rest assured
    testImplementation 'io.rest-assured:rest-assured:4.3.3'
    testImplementation 'io.rest-assured:json-schema-validator:4.3.3'

Step 6 – Below are the Rest Assured, json schema validator, junit jar files present under Maven Dependencies.

Make sure you right-click on project -> Select Gradle ->Refresh Gradle Project. It is needed to see the new jar files in the project.

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers

TestNG Framework – How to download and install TestNG in Eclipse

HOME

In the previous tutorial, we discussed what is TestNG and why it is important. This tutorial will discuss how can we download and install TestNG in Eclipse and how to use it.

Pre-Requisite 

1) Eclipse should be installed and configured. Please refer to Install and Configure to set up Eclipse on your system.

Install/Setup TestNG

1) Launch Eclipse and go to the “Help” option present at the top and select –“Install New Software”.

2) A dialog box will appear, click the Add button.

3) A new dialog box will appear. Mention the Name as TestNG and the location asTestNG P2 – https://testng.org/testng-p2-update-site” and click the Add button.

4) This time we will see TestNG is added to Install dialog box.

5) Accept the terms and conditions and then click the Finish button.

6) Once the installation is completed, you will get a message to Restart the Eclipse. Select Restart the Eclipse

7) To verify if TestNG is installed successfully or not, go to Window, select Show View, and then Other.

8) Select Java and see, within the Java folder, you will see TestNG. This shows that TestNG is successfully installed on the machine.

Steps to follow to create a TestNG class

1) Create a new TestNG class. Right-click on the Folder where you want to create the TestNG class. Select TestNG and then Create the TestNG class as shown in the below image.

2) In the below image, we can see that the Source folder is the name of the folder we want to create the class, and we can mention the name of the class in the Class name. Under annotations, I have checked @BeforeTest and @AfterTest and click the Finish button.

3) We can see that the structure of the new TestNG class looks like as shown below.

4) In the below example, we want to navigate to an Amazon page and search for Hard Drive.

@BeforeTest : Launch Firefox and direct it to the Base URL

@Test : Search for HardDrive

@AfterTest : Close Firefox browser

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;

public class TestNG_Demo {

   public WebDriver driver;

   @BeforeTest
    public void beforeTest() {
      
     System.setProperty("webdriver.gecko.driver","C:\\Users\\vibha\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("https://www.amazon.com//");
 }

@Test
public void Validation() {
    driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']")).sendKeys("hard drive");
    //XPath for search button
      driver.findElement(By.xpath("//*[@class='nav-input']")).click();
   }

@AfterTest
public void afterTest() {
    driver.quit();
  } 
}

5) To execute this program, we need to Right-click and select Run as – TestNG Test.

6) The result will look like something shown below. Here, we can see that Test Case Passed is 1, Failed 0, and Skipped 0.

7) As we know that TestNG also produce HTML Reports. To access the report, go to the Eclipse folder, and you can see a folder with name test-output inside the Project where we have created TestNG class. Here, it is  C:\Users\vibha\Downloads\eclipse-workspace\Demo

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!