In this Gradle Tutorial, we will look into what is Gradle, few major advantages of Gradle and how to write and execute our test into eclipse using Gradle.
Gradle is open-source Build management and automation system based on Groovy-based Domain-specific language instead of XML files, unlike maven or ant. It is been created and disturbed by Apache.
What
is Gradle?
Gradle is open-source Build management and automation system based on Groovy-based Domain-specific language instead of XML files, unlike maven or ant. It is been created and disturbed by Apache.
Advantages of Gradle
รผ Dependency and distribution
management.
รผ Integration with Source
code management tool like GIT.
รผ We can build scripts
with a functional programming language.
รผ Single Build tool to support
multiple programming languages.
รผ It has DSL for creating
and writing build tasks.
In
this section we will be creating our first Java Selenium program along with
TestNG and Gradle as a build automation tool.
To
Start working with Gradle we need to install Gradle plugin into our eclipse for
that we need to follow below steps:
1) In Eclipse Click on Helpร Eclipse Market Place.
2) Search for Gradle
Plugin
3) Install the plugin if
already not installed. Please make sure to restart your eclipse after
installation.
Now
to Create our first Gradle project in eclipse we need to perform the below steps:
1) Fileร Newร Project type Gradle in wizards.
2) We will get option of
Gradle project. Please select that.
3) Click on Next and provide
name of the project
4) Click on Finish.
Now
we would be able to see that along with our basic project structure there are
two more new files named “build.gradle” and “settings.gradle” are generated.
build.gradle
is the heart of our project in which we need to specify all our dependencies, plugins
and repository information the same way we do it in our maven project.
We
can also delete the by default package created in src/java and src/test folder.
Now
to start working with the Gradle project we need to put the Gradle dependencies in
our build.gradle file.
In
this section for learning purpose I would be creating simple selenium program
along with TestNG.
For
this purpose we need to go to maven repository and copy the Gradle dependencies
of selenium and testing.
This
dependencies we need to copy into the dependencies section of our build.gradle
file.
Once
this is done we need to click to do right click on project ร Gradleร Refresh Gradle project
this will download all the dependencies in our local.
Now we can create any selenium program for e.g to enter any value in google home page along with its corresponding testing.xml file as well.
Now
to execute this we have two options.
1) We can directly execute this with the help of testing.xml as we usually do.
2) In Our build.gradle we can create one new task lets name it as a test in this we need to give values like.
To execute this right-click on build.gradle, Select Run as ร Run configurations.
Here we need to select our gradle project and in arguments Tab, we need to run the command gradle test.
1) We can directly execute this with the help of testing.xml as we usually do.
2) In Our build.gradle we can create one new task lets name it as a test in this we need to give values like.
To execute this right-click on build.gradle, Select Run as ร Run configurations.
Here we need to select our gradle project and in arguments Tab, we need to run the command gradle test.
Now click on run to execute our first Gradle test.
Happy Learning...!!!
Happy Learning...!!!