How to Create Maven Archetype


Hello all, I have been automating web and mobile apps for a long time. The first step of my automation journey starts with copying and pasting our base classes into the new project. Those base classes generally contain base Selenium methods, intelligent waits, string /date and DB utility classes and browser executables. So why not automate our project creation by creating our custom Maven Archetype? Here’s how you can create a Maven Archetype for your automation projects.

Step 1: Creating a Sample Project

Create a clean Maven project with all the necessary classes, executable, etc inside of it.

In this example, I also have some example PageObjects and Test Classes for newbies to understand how we handle automation logic.

Step2: Creating and Editing the Archetype

This archetype’s name will always contain the project name written in pom.xml file. In our example, it’s selenium that’s why archetype name is selenium-archetype.

By using the terminal, go to project folder containing pom.xml file and execute this command.

mvn archetype:create-from-project

At the end of execution, you will have BUILD SUCCESS message and you will notice that an archetype is created.

Go to the project folder and you’ll notice a target folder is created. Under it, there are many folders as follows “generated-sources/archetype/….”. Under the archetype folder, we have a maven project structure with a new pom.xml.

Move this archetype folder to a new folder because we are going to work on it and I don’t want you to get lost between folders 🙂

Let’s deep dive into this folder and see what do we have under it!

What’s in archetype-resource Folder?

As you can see, under archetype-resource folder we have our base project folder created with everything we need. Go to the highlighted pom.xml file under archetype folder and open it.

groupId, artifactId, version, name tags are parametrized. Those parameters will be set on the command line or on IDE while trying to create Maven project.

What’s in Maven Folder?

Under this folder, we have archetype-metadata.xml file where you can edit the content of the project structure. You can change which folder to include or exclude from project, file type to exclude or include. I leave it as it is cause I need all of those files.

Step3: Including Our Archetype to Local Maven Catalog

Go to your new folder containing pom.xml file and execute below command:

mvn install 

At the end of execution, BUILD SUCCESS message will appear and Local Maven Catalogue is updated with your maven archetype.

Step 4: Creating a New Project with New Archetype

 Go to an empty folder and run below command to create a project with our custom archetype.

mvn archetype:generate

-DarchetypeGroupId=com.sahabt

-DarchetypeArtifactId=selenium-archetype

-DarchetypeVersion=1.0-SNAPSHOT

-DgroupId=com.sahabt

-DartifactId=automation

-Dversion=1.0-SNAPSHOT

By using groupdId, artifactId and version parameters, we set pom.xml related parameters.

Other parameters define the archetype.

Enjoy your archtype 🙂

javafx

Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! http://www.swtestacademy.com/getting-started-with-javafx/ At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
selenium

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 5 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...
selenium

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...
javafx

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...
selenium

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across the wide range of browsers and platforms. In this tutorial, you will learn how to do web test automation with Selenium Webdriver and the related tools....
selenium

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...
selenium

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...

Getting Started with RobotFramework on Windows

By Onur Baskirt / Apr 25, 2016 / 12 Comments
What is RobotFramework? RobotFramework is a GENERIC test automation framework for acceptance testing and acceptance test-driven development (ATTD). What it means that you can do web, mobile, desktop and other test automation activities with related test libraries. These libraries can...
By | 2017-07-14T13:31:07+00:00 July 14th, 2017|Test Automation|0 Comments

About the Author:

Canberk Akduygu
Canberk Akduygu is working as a Technical QA Architect on test automation and performance testing. Formerly, he worked at TEB as QA Project Lead, Ayrotek IBM Business Partner and Yapi Kredi Bank as Java Developer. You can also follow him on Linkedin.

Leave A Comment