Framework Setup

Creating the Maven Project

  1. Launch IntelliJ and select ‘Create New Project’
  2. Select ‘Maven’ in the left pane
    1. Select the appropriate Java JDK in the ‘Project SDK’ dropdown at the top (should be the one installed previously)
    2. Click ‘Next’
  3. In the ‘GroupId’ field, enter an appropriate name (e.g. “com.producttestframework”)
  4. In the ‘ArtifactId’ field, input an appropriate name (e.g. “AutomationFramework”)
  5. Click ‘Next’
  6. Give an appropriate Project Name (e.g. “ProductAutomation”) and an appropriate project location on your local machine (e.g. ~/Users/username/DevProjects/ProductAutomation)
  7. Click ‘Finish’
  8. Advance to IntelliJ IDEA –> Preferences/Settings –> Build, Execution, Deployment –> Build Tools –> Maven –> Importing (will be slightly different depending if you’re on Mac or Windows)
    1. Ensure ‘Import Maven projects automatically’ is checked

Maven Dependencies

You can manage all your projects dependencies, plugins and packages by simply adding them into your Maven project’s POM.xml file 🙂

  1. Open up the POM.xml file and add the following source and target properties within the <project/> tags…
  2. Open up the POM.xml file and add the following dependencies within the <dependencies> tag section. If you do not see any <dependencies/> opening and closing tags, simply add them within the <project/> tags.

Please note that the latest versions may change since the date I wrote this guide.  I recommend searching for each dependency below on https://mvnrepository.com and simply copying the dependencies from there and then pasting them into your project’s POM.xml file.

Do make sure however, that you include certain information like ‘exclusions’ for JUnit in the TestNG dependency as shown in my examples below.

Cucumber Dependencies

Cucumber-Java

Cucumber-JVM-Deps

Cucumber-TestNG

Cucumber-Reporting

TestNG Dependencies

TestNG

Selenium WebDriver Dependencies

Selenium Java

WebDriver Manager (used to automatically grab the necessary Selenium Drivers when creating an instance, rather than manually setting a path to them)

Extra Needed Dependencies for Drivers

Google Core Libraries for Java

Gson

Log4J Logging

Log4J-Core

Log4J-API

Maven Plugins

Please again note that the latest versions may change since the date I wrote this guide.  I once again recommend searching for each plugin listed below on https://mvnrepository.com and simply copying the plugins from there and then pasting them into the <plugins> tag section in your project’s POM.xml file.

Do again make sure however, that you include all the specific information in my examples.

  1. In the same POM.xml file, add <plugins/> tags within added <build/> tags, and then add the following plugins within the <plugins/> tags. Again add all this outside of the <dependencies/> tags but within the <project/> tags

Maven-Surefire-Plugin

This plugin can be used for reporting and is also used in our test framework to configure where our test suites are run from (e.g. testng.xml)

IntelliJ Plugins

Cucumber for Java Plugin

  1. Ensure ‘Cucumber for Java’ plugin is installed and enabled in IntelliJ by going to Settings –> Plugins and ensuring ‘Cucumber for Java’ is checked
    1. MacOS: IntelliJ IDEA –> Preferences –> Plugins
    2. Windows: File –> Settings –> Plugins

Create a .gitignore File

  1. In IntelliJ, right-click on your project root and select New –> File
    1. Name the file .gitignore and click OK
  2. Paste the following into your .gitignore file (this is a default template used for Maven projects)

    Now would be a good time to save the Maven project if you haven’t yet done so! 🙂

Packages & Directory Structure

  1. Right-click on the {project-root}/src/test/java directory, select New –> Package, and add the following packages (as well as sub packages within other packages.  You may need to put a temporary dummy file in ‘utils’ package first before adding the sub-packages)
    • pages
    • steps
    • utils
      • drivers
      • extensions
      • helpers
      • hooks
      • selenium
  2. Right-click on the {project-root}/src/test directory, select New –> Directory
    1. Name the directory ‘resources’ and click OK
  3. Right-click on the {project-root}/src/test/resources directory and select ‘Mark Directory As’ –> ‘Test Resources Root’ (if not marked already)
  4. Right-click the /src/test/resources directory again and select New –> Directory
    1. Name the directory ‘features’ and click OK

Initial Files in each Package / Directory

Features folder

  1. Right-click the ‘features’ directory, select ‘New’ –> ‘File’ and add the following feature files (Feature files is what Cucumber uses to write BDD scenarios using Gherkin language. Please see https://cucumber.io/ for more information)
    • BaseScenarios.feature

Pages package

  1. Right-click the ‘pages’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘pages’ package will contain all our class files for our web pages / page objects, following Page Object Model (POM) principles. Please see https://goo.gl/4iq2Et for more information)
    • Page
    • BasePage

Steps package

  1. Right-click the ‘steps’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘steps’ package will contain all our step definitions, which acts as the glue that connects our BDD/Gherkin language scenarios in our Feature files, to our test methods in our Java classes.  Please see https://docs.cucumber.io/cucumber/step-definitions/ for more information)
    • BaseScenariosSteps
      • this class contains all the step definitions for your base scenarios
    • BaseSteps
      • this is simply an empty placeholder class which inherits from the ‘Page’ class, to follow POM principles
    • DynamicTableSteps
      • this class contains all the step definitions for scenario lines which contain dynamic data tables
    • NonDynamicTableSteps
      • this class contains all the step definitions for scenario lines which contain non-dynamic data tables
    • ReturnClickSteps
      • this class contains all the step definitions for scenario lines / test methods which return a new Page Object when a web element is clicked on
    • SendKeysSteps
      • this class contains all the step definitions for scenario lines / test methods which sends keys / a string to a web element
    • ValidationSteps
      • this class contains all the step definitions for our test assertions
    • VoidClickSteps
      • this class contains all the step definitions for scenario lines / test methods that do not return anything (void) when a web element is clicked on

Utils package

Drivers package

  1. Right-click the ‘drivers’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘drivers’ package will contain class files for all the different WebDrivers our test framework will use)
    • ChromeWebDriver
    • FirefoxWebDriver

Extensions package

  1. Right-click the ‘extensions’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘extensions’ package will contain class files for all our static methods that we can use as extensions to our existing functionality)
    • GeneralExtensions
    • JavascriptExtensions
    • JqueryExtensions
    • JquerySelectorExtensions
    • WebDriverExtensions
    • WebElementExtensions

Helpers package

  1. Right-click the ‘helpers’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘helpers’ package will contain class files for all our static methods which can act as helpers to our existing functionality)
    • GeneralHelpers
    • JavascriptHelpers

Hooks package

  1. Right-click the ‘hooks’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘hooks’ package will contain classes for all the different hooks we can run before and/or after test runs/suites/scenarios etc.)
    • CucumberHooks
    • StepHooks
    • TestRunHooks

Selenium package

  1. Right-click the ‘selenium’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘selenium’ package will contain our core WebDriver setup and DriverController instance, as well as a Settings class where we can list public static variables to be used in our project)
    • Driver
    • DriverController
    • Settings
Digiprove sealCopyright secured by Digiprove © 2018
Liked it? Take a second to support Thomas on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.