The purpose of this project is to automate UI tests of the website, https://www.theredx.com/ using Java & Selenium with Maven.
This framework uses the following:
- Java - version 12
These should all be part of the pom.xml file.
- Maven.compiler - version 1.2
- Selenium - version 3.141.59
- Test NG - version 6.14.3
- Surefire - version 3.0.0-M5
- Page Object Model - if you haven't used the Page Object Model before, check out the Page Object Model section below.
You will need the following on your computer in order to work on this project:
- Java - Using version 12 for this project
- Maven - Check out the Maven section below for more info on installing it
- Open the terminal
- Navigate to the directory you want to store this project
- Run this command
git clone https://github.com/vernko/redx-demo.git
- Once it has cloned the repo, you should see something like
redx-demo git:(main)
- Now you know you have the code for the repo on your machine
- Open this project in the code editor of your choice (for java, IntelliJ is really nice, recommend downloading the free community version at https://www.jetbrains.com/idea/download/)
- Once you have the project open, check & make sure you have the right version
- Packages - camelCase (typically only one word though)
- Classes - PascalCase
- Methods - camelCase
You'll find any Page Objects under the "main" directory in the "pages" package.
Essentially, for each page you create a new class. You can use that class object anywhere in the automation. We use these classes to put any selenium-based operations such as:
- Locators
- Clicks
- Sending keys/inputs
Add methods & locators related to that page inside this class.
I prefer to organize these in a hybrid alphabetical/functionality order.
- If there is no related functionality, order it alphabetically.
- If there is related functionality, put that in order of occurrence.
You'll find any tests under the "test" directory.
- Each page is a separate test package.
- Each package has a test class to hold all the tests
- All tests are separate methods within the test class.
This framework uses TestNG. If you aren't familiar with TestNG. Check out the TestNG section below for more info.
With TestNG, every test is its own method with the notation of @Test
.
Just like with methods in a Page Object class, organize these in a hybrid alphabetical/functionality order.
- If there is no related functionality, order it alphabetically.
- If there is related functionality, put that in order of occurrence.
- A descriptive name for the test
- Test data/info needed for validation of tests
- Clean descriptive steps (aka methods from page object class)
- Assertion - whatever you are validating to ensure the test passes as you expect.
TestNG provides an "Assert" class with a variety of asserts including:
- assertEquals
- assertTrue
- assertFalse
- assertNotEquals
If you need to create new tests related to a group of test already created, go to that test class, and add the new test there.
If you need to create a test that does not relate to a current test. Add a new package for that particular page, then add the new test.
For example, if you need to add a test for filling in the contact info on the About Me page. We might do something like this.
- Go to test -> java
- Create a
aboutMe
package - Create a
AboutMeTests
class under theaboutMe
package. - Make sure
AboutMeTests
extends the correct class, in this case that would beBaseTests
. - Add a new test, named something like
testCanSumbitContactForm
- Add test steps
- Assert that form was submitted
@Test
public void testCanSubmitContactForm(){
# Go to About Me
# Fill out contact form
# Submit that form
# Assert form was submitted
}
From IDE
- Go to the test class of the test you want to run
- Find the test (aka test method) you want to run
- Click the play button next to the test
From Command Line
To run tests from the command line, you'll need to have mvn
installed on your device.
Once you have maven installed on your device, run mvn -v
. This verifies maven installed.
- Test Class - run all the tests in an entire class
mvn test -Dtest=ClassName test
There are 2 ways to run the entire suite for automation
XML File
- Find the "aumniAutomationSuite.xml" file
- Run the suite of tests.
Command Line
mvn test
If you don't have maven installed on your device, check out this article to help install it on your device. Install Maven
For mac users, you can install maven view Homebrew by running this command brew install maven
Below are some good resources to help with Test NG if you have never used it before.
TestNG's official site - TestNG
A good tutorial Test Automation University - Intro to TestNG
If you haven't used Selenium before, basically it's a tool that helps to help automate tasks. In testing, we use it to help automate user flows especially web-related items.
Selenium's official site - Selenium
The article below from BrowserStack provides good info about the POM - Article on POM