Qashowcase
A showcase of my QA abilities by creating an automation framework using Java, Selenium, TestNG. In short: this framework will be a BDD-POM hybrid framework with support for API and database testing.
Install / Use
/learn @h1ddengames/QashowcaseREADME
QA Showcase
A showcase of my QA abilities by creating an automation framework using Java, Selenium, TestNG. In short: this framework will be a BDD-POM hybrid framework with support for API and database testing.
Important note: in the process of building up the framework from scratch, it's unavoidable that there will be files leftover to represent what the framework looked like at an earlier point. Additionally, I have decided to keep multiple versions of the POM implementation within the framework. It is up to the automation framework architect to decide which version to implement based on the needs of the company they work for.
This framework will include the following:
<details> <summary> <b><i><u>Click me to display this section</u></i></b> </summary> <p>- POM (Page Object Model) - To separate function driven methods into several classes as well as using PageFactory to find elements.
- Object Repository - To store WebElement locators in properties files.
- BDD/BDT (Behavior Driven Development/Testing) - To abstract away the difficulty of creating test scripts by using Gherkin.
- Rest API Testing - To test REST API using Rest Assured.
- Database Testing - To test a mysql database using JDBC.
- Cross-browser Testing - To run tests on multiple browsers at the same time.
- Jenkins (CI/CD) - To run tests based on certain criteria (new code has been pushed, it is after work hours, etc)
- Selenium GRID/Browser Stack (parallel distributed testing) - To run tests on a distributed environment either locally (GRID) or on a service (Browser Stack).
This framework will be missing the following (for now):
<details> <summary> <b><i><u>Click me to display this section</u></i></b> </summary> <p>-
Note that while I provide only these options, there may be many more. There is no right or wrong way of implementing these types of frameworks, it all just depends on your situation (the website being tested, your script creators, complexity of the test cases, etc)
-
Mobile Testing - If you wanted to implement this yourself, you have these option(s):
- You can use Appium (which has similar syntax as Selenium) in order to do mobile testing.
-
KDD/KDT (Keyword Driven Development/Testing) - If you wanted to implement this yourself, you have these option(s):
-
Create an Excel spreadsheet with a format that your test team can agree with.
<details> <summary> <b><i>Excel keyword framework data format... <u>click me to display</u></i></b> </summary> <p>| Step | Locator | Action | Data | |------|------------------------|-------------|------------------------| | 1 | LINK_TEXT:Login | CLICK | | | 2 | ID:spree_user_email | SEND_KEYS | shift@gmail.com | | 3 | ID:spree_user_password | SEND_KEYS | shiftedtech | | 4 | NAME:commit | CLICK | | | 5 | CSS:.alert-success | VERIFY_TEXT | Logged in successfully |
</p> </details>-
Use Apache POI to read this Excel data.
<details> <summary> <b><i>Reading Excel data code... <u>click me to display</u></i></b> </summary> <p>
</p> </details>String file = <fileLocation> ExcelReader reader = new ExcelReader(file); String[][] data = reader.getExcelSheetData(0, true); for(int i = 0; i < data.length; i++) { String index = data[i][0]; String locator = data[i][1]; String action = data[i][2]; String testData = data[i][3]; System.out.println(String.format("Index: %s Locator: [%s] Action: %s TestData: %s", index, locator, action, testData)); }
-
-
-
DDD/DDT (Data Driven Development/Testing) - If you wanted to implement this yourself, you have these option(s):
-
Create a method that returns a two dimensional array then mark that method using TestNG's @DataProvider to feed this data into a parameterized test.
-
Use Apache POI to get data from an Excel spreadsheet then use that data in a parameterized test using TestNG's @DataProvider.
-
You can create a test script generator using Java where you feed the generator a bunch of test data. For each "unit" of test data that you input, it will create a test case using a "default" structure. With each different test, it will replace the parameters you want with the test data.
-
Example:
<details> <summary> <b><i>Test script generator... <u>click me to display</u></i></b> </summary> <p>
</p> </details>// Sample default structure @Test() public void test<id>() { homePage.goToLoginPage(); loginPage().login(<username>, <password>); homePage().verifyLoginSuccess(); } // Test script generator will generate the following: // Auto generated test script @Test() public void test1() { homePage.goToLoginPage(); loginPage().login("shift@gmail.com", "password"); homePage().verifyLoginSuccess(); } // Auto generated test script @Test() public void test2() { homePage.goToLoginPage(); loginPage().login("shiftqa@gmail.com", "password1"); homePage().verifyLoginSuccess(); } . . . // Auto generated test script @Test() public void test999() { homePage.goToLoginPage(); loginPage().login("shiftqa00312@gmail.com", "someR32#ndao@OmPaswowerd"); homePage().verifyLoginSuccess(); }
-
Setting up a Framework from Scratch
<details> <summary> <b><i><u>Click me to display this section</u></i></b> </summary> <p>- Create a Maven project.
- Create proper project structure.
- Setup local maven repository, proxy, mirrors, and repositories.
- Add required dependencies into pom.xml
- Setup custom test reporting (Extent or Allure reporting or create your own reporting)
- Create a driver factory that supports ThreadLocal so all your tests can be run in parallel.
- The driver factory should make creating and using a WebDriver as simple as possible.
- Allow users to choose which WebDriver to use when creating a driver.
- Allow users to choose between headless or GUI WebDrivers.
- Setup cross browser testing by creating a testng.xml runner that utilizes parameters.
- Implement the POM (Page Object Model) framework.
- Navigation (and other WebElements that remain the same from one page to another should be the base class/super class)
- Each page of the company website should have it's own class and these classes should all extend the navigation page class.
- Implement a function driven framework where each page has several steps of a test wrapped into it's own function.
- For example in the Login page class, create a function that takes in a String username and String password. The username and password fields are cleared of any previous text stored. Next, the function enters those Strings into the username and password field respectively. Finally, the login button is clicked.
- Implement the BDD (Behavior Driven Development/Testing) framework.
- Implement Rest Assured for API testing.
- Implement Karate for BDD style API testing.
- Implement the JDBC (Java Database Connector) for database testing.
- Has an added benefit of being used for Keyword and Data Driven Development/Testing.
- Generate tests using AssertJ, Selenium, and TestNG.
- Setup Selenium Grid and/or Browser Stack based on company's requirements.
- Setup Jenkins or Bamboo as a CI/CD pipeline based on company's requirements.
1. Create a Maven project
<details> <summary> <b><i><u>Click me to display this section</u></i></b> </summary> <p>- Using IntelliJ IDEA, click on New > New Project.
- Select Maven > Next.
- Provide a GroupId in reverse order (if your company's url is google.com then you should make the GroupId "com.google")
- Provide an ArtifactId based on the project you are working on then click Next.
- Provide a project name and location then click Finish.
2. Project folder structure
<details> <summary> <b><i><u>Click me to display this section</u></i></b> </summary> <p>-
The testcases package contains random test cases just to make sure that the project works with all the dependencies.
-
The hybridtestcases package is to make sure the framework has been implemented properly.
-
The com.shiftedtech.spree package contains all tests related to the website http://spree.shiftedtech.com
-
The com.shiftedtech.heatclinic package contains all tests related to the website http://heatclinic.shiftedtech.com
-
All test scripts belong in src/test/java
-
All framework scripts belong in src/main/java
<details> <summary> <b><i>Framework layout... <u>click me to display</u></i></b> </summary> <p>
</p> </details>- pom.xml - src - main - java - com.h1ddengames.framework // All framework files belong here - pages - BasePage - HomePage - LoginPage - All other page object model files belong here - steps - All step definition files belong here - utils - All utility files belong here - resources - All properties files for different environments belong here - Any properties files for custom reporting belong here - test - java - com.h1ddengames - bdd - All bdd runner files go here - resources - log4j.properties - testng-simpletest.xml
