Automation accelerator framework written in java. This project demonstrates a variety of automation examples including: web UI, mobile UI, API automation, database interaction and various automation test runners (Cucumber, TestNG, etc).
This framework can be used as a reference for implementing new functionality into an existing automation framework.
It can also be used to kick-start your automation if you don't have automation in place.
All in all, the java-automation-accelerator
is a physical example of best practices and approaches to test automation.
Required
Optional
Since this is a Java project, it can run on most major operating systems. These include:
- Mac OS X
- Windows
- Linux
Once all dependencies are configured and the java-automation-accelerator code downloaded, it should be ready to run. Maven is used to manage both dependencies and compiling the solution. For more info, see the maven documentation
All of the Maven configuration is specified in the pom.xml (located at the project root). This is where we pull selenium, appium, junit, cucumber and all libraries needed to build and run this solution. Below are the most relevant maven commands:
# Clean the compiled 'target' folder
mvn clean
# Install the dependencies specified in the pom.xml
mvn install
# Clean and install the dependencies
mvn clean install
This framework showcases various libraries that are commonly used to run automated tests aka 'Test Runners'.
Each of these test runner implementations are designed independently of one another and can be found in the test package: src/test/java
.
Below are the test runners implemented in the accelerator:
- Cucumber - BDD framework that utilizes Gherkin syntax to make tests more readable.
- JUnit - Perhaps the mostly widely used Java automation library, JUnit is primarily a unit testing framework with a lot of flexibility.
- TestNG - Similar to JUnit with some extra functionality.
NOTE: In terms of implementing automation for your project - pick just 1 of the test runners. If you would like to use more than one runner for you project (NOT Recommended), then split them up into separate code bases.
There are two core concepts in cucumber: features and step definitions.
Features are the .feature
files which define tests in a human readable format.
For each step in the feature file, there must be a corresponding 'step definition'. The step definition binds to a feature file step and executes test code.
In this solution, feature files are located at src/test/java/resources/cucumber/features
and step definitions are located at src/test/cucumber
.
Furthermore, Cucumber requires a 'test runner' and 'hooks' class. The test runner is the entry point when running cucumber tests.
It tells cucumber where the step definitions and feature files are located. It is also for configuring the reports and tags.
For example, the test runner for web tests is located at src/test/java/cucumber/web/support/CucumberWebTestRunner.java
.
The hooks class is used to execute specific logic on a per tag, per scenario or per feature basis.
An example of this is located at src/test/java/cucumber/web/support/Hooks.java
In order to run cucumber tests via the IntelliJ IDE, below are the steps. This is for web tests, but it is the same process for API/Mobile cucumber tests.
- Open IntelliJ
- Import the
java-automation-accelerator
project as an existing Maven project - Open the IntelliJ terminal: View > Tool Windows > Terminal
- Clean and install the Maven dependencies
mvn clean install
- Ensure the install finishes with SUCCESS.
- Open the Cucumber Web Test Runner class:
src/test/java/cucumber/web/support/CucumberWebTestRunner.java
- Click the green play icon in the left hand gutter of the CucumberWebTestRunner.java file (next to line numbers).
- Select either 'Run CucumberWebTestRunner' or 'Debug CucumberWebTestRunner'. Debug will enable breakpoints.
- The test should be running in the Chrome browser by default.
- Open Terminal (OSX) or Command Prompt (Windows)
- Go to the
java-automation-accelerator
source code directory:cd <path>\<to>\java-automation-accelerator
- Install Maven dependencies:
mvn clean install
- Ensure the install finishes with SUCCESS.
- Run the Cucumber tests:
# Running on Chrome browser mvn clean install -Dtest=CucumberWebTestRunner test
There are two core concepts in TestNG: testng.xml
and test classes. testng.mxl
is the driving file that defines
tests to be run. Tests can be run in groups with a number of tags and annotations. Although less readable than cucumber, it's
efficient for those more seasoned in code. The test classes can each house multiple test cases, separated by tags.
In this solution, testng.xml
file and it's associated classes can be found in the
src/test/java/testng folder.
In order to run TestNG tests via the IntelliJ IDE, below are the steps. This is for web tests, but it is the same process for API/Mobile TestNG tests.
- Open IntelliJ
- Import the
java-automation-accelerator
project as an existing Maven project - Open the IntelliJ terminal: View > Tool Windows > Terminal
- Clean and install the Maven dependencies
mvn clean install
- Ensure the install finishes with SUCCESS.
- From the configurations drop down at the top right of the IntelliJ window, select TestNG.
- Click the green play button next to the dropdown.
- Which test cases are being run can be altered in the testng.xml file.
TODO
TODO
TODO
TODO
Below is information regarding the design and structure of various features within the framework.
For mobile and web UI automation, we follow the Page Object Pattern. The general idea is that for a given web or mobile app, there should be a class for each screen (mobile) or page (web) that contains code relevant to the app page/screen.
For example, for a Login PageObject class you might have methods for logging into the app with email and password. You would also place all selectors for the login page within this class. This structure allows easier code maintenance and should be more intuitive as the page objects should follow the application.
TODO
- REST vs SOAP
- Sending requests
- Receiving responses
- Manipulating response objects
TODO
- Using the JDBC and patterns for DB connections in a re-usable way
- MSSQL, PSQL, etc libraries
TODO
- How docker works
- Why docker is useful and the purpose it serves
- The types of containers used by this project (dependencies, etc)
- All classes should be named in PascalCase where the first letter of every word should be capitalized. Example: ClassName.java
- All methods should be camelCase where the first letter is lower case and every word after is uppercase. Example: methodNameExample();
One of the essential code practices is the idea of reducing duplicate code by adhering to DRY principles. If you use the same block of code in more than one place - put it into a class/method so that there is only 1 place to update the code instead of several. This makes the framework much more robust with easier maintenance and quicker test development.
Doing regular code reviews with members of your team (development or QA) is a great practice to follow. When using GIT, one of the best ways to accomplish Code Reviews is in the form of Pull Requests. Essentially, when you check in a new commit to the repo - send it as a pull request. This way, another person must merge the code into the given branch, instead of yourself.
TODO
- Pull Requests (code reviews)
- GitFlow branching strategy
- Etc
TODO
- Storing as static files
- Dynamically pulling from database or API
- Best practices
TODO
- Integration with CI/CD pipeline using docker
TODO
- Discuss various reporting options - both custom and canned reports
In order to build UI automation, you'll need to inspect the application source to find unique identifiers for Selenium/Appium to interact with elements.
Chrome comes with 'Developer Tools' which are an excellent feature for inspecting web elements. Open up Chrome, click 'Help' in the toolbar and search 'Developer Tools'. For more information, see devtools documentation.
Appium provides a desktop application designed specifically for inspecting Android and iOS UI elements. It is called Appium Desktop. For instructions and download, go here
TODO - add wiki pages for documentation and add a list of links to the pages.