Useful testing tools for API frameworks

Senior Software Development Engineer in Test (SDET) at BP, Gabriel Ng, explains what tools to consider when designing and scaling a robust application programming interface (API) framework

Ng is a dedicated Engineer/Developer in test who has had the opportunity to work in multiple roles, including Quality Engineer, Technical Consultant and QA Lead within government, financial, oil, retail and gaming services.

His current client role includes architecting test solutions, defining test dependencies, implementing test automation frameworks across API and UI layers, leading test strategy, as well as risks and approaches to deliver a robust solution alongside other smart engineers. Overall, he acts as the quality gates to govern all test environments and production releases.

“Although I started my career within software development, I eased into the world of test automation quite quickly and fell in love with such a niche field with an enormous ecosystem,” said Ng.

Utilising tools

Nevertheless, he finds that keeping up-to-date with the latest tools can be difficult, despite there being various tools which can be utilised.

“I would recommend using Gradle dependency management for any Java Test projects to ensure test tools are always up-to-date; it is flexible, yet quick to implement and helps manage test dependencies in a single build script. As for JavaScript and NodeJS test projects, NPM (Node Package Dependency) comes out of the box where latest node modules can be fetched by simply specifying specific node modules versions,” advised Ng.

“My current tech stack includes Azure, VSTS for release, builds and pipeline management, Java, Serenity BDD, RestAssured for API Test Automation and Protractor, Typescript, Selenium, WebdriverJS for Angular UI Test Automation; all of which sit under JVM Cucumber and Cucumber JS following the BDD test approach.”

Why use Selenium?

Although the growth of Selenium has evolved dramatically over the years’, he still recommends Selenium for UI testing for the following reasons:

  1. It’s growing modern browser support, we would not need to worry about new browsers breaking test as Selenium would partially handle this with its WebDriver implementation
  2. Selenium Grid, Remote WebDrivers, out of the box Selenium provides the ability to execute tests on any remote browsers, integrating with any cloud-based platforms easily
  3. Flexible to use and refactor, design patterns such as Page Object Model, Object Repository can complement extremely well with Selenium test scripts, allowing flexibility to refactor classes and objects as desired
  4. Portability and Language support, Selenium is available across almost all modern programming languages such as Java, JavaScript, C#, Python, Ruby, PHP, Perl Groovy, this provides great portability for implementation in any types of projects
  5. Furthermore, the test script can be run with many CI platform such as Jenkins and supported by cloud platforms.

Selenium and the cloud

In order to utilise Selenium with cloud platforms, he uses two main test platforms ‘Browser Stack’ and ‘Sauce Labs’. According to him, both cloud platforms can easily be utilised when executing UI Selenium test scripts, performance and load testing.

Ng continued: “These platforms will decrease script execution time vastly at the same time provide support for over 700 different browsers and mobile platforms.

“By running tests in the cloud, this will also reduce overheads costs such as maintaining and house Selenium Grid. Through cloud capabilities, there are great benefits when trying to scale across various types of browsers and mobile platform; all within configuration files.

“As we evolve into user-centric testing to ensure compatibility, accessibility bugs are identified early on and cloud capabilities will help leverage this and bring test implementation to the next level.”

Security monitoring tools

As all tools are open source these days, he recommends integrating security monitoring tools such as ‘Black Duck’ to scan for any open source libraries vulnerabilities to ensure projects are not at risk to security risks and follow trusted and industry standard advice.

When designing and scaling a robust API framework, Ng believes it’s important to consider the below components:

  1. Test scripts, test data JSON bodies: Used for configuration files and resources to act as resources that drive and execute test scripts
  2. Automation toolset: Automate, make calls and interact with REST/SOAP API endpoints
  3. Common libraries and helper classes: Use database classes, assertion classes, data readers and JSON loaders to take away the implementation from test scripts and increase code reusability
  4. Execution environments: Where will the test scripts execute in containerised environment architecture? A cloud-based platform?
  5. Test reporting: How do you best represent test results? Currently, Cucumber Reports are the most popular to provide step by steps expectation of pass-fail features and scenarios derived from Cucumber Feature files.

Validating APIs

On a high level, Serenity BDD out of the box provides a comprehensive list of helper functionality, professional test reporting, test environments, and integration and test scripts management where Cucumber JVM is at the heart of driving BDD test scripts. API request and responses can also be captured easily using special Serenity annotations to represent these test results in Serenity Report through the usage of Serenity Step libraries.

Using Serenity Rest and the core wrapper class of RestAssured provides great functionality when interrogating and validating APIs such as the handling of API security, advanced JSON request, response, object types and asserting an API response status; allowing code reusability throughout the test framework.

“Recently, I have adopted the usage of Typescript in my UI Test Framework. Typescript is a superset of JavaScript which is introduced by Microsoft to provide optional static typing, classes and interfaces. These functions are core to implementing a scalable and robust test framework,” commented Ng.

“For Angular projects, I would recommend Typescript with Protractor as the UI Automation tool, following the Page Object Model design pattern. Protractor is simply a wrapper around WebDriver JS which contains all the benefits of core Selenium including the ability to integrate with remote browsers and Selenium Grid.”

Test-reporting processes

“Protractor also provides additional Angular specific wait functions, element selector types and page bindings. Additionally, Protractor would work well with any assertion libraries such as Mocha and Jasmine, alongside Cucumber JS, Serenity JS, which allows true flexible integration across the UI automation stack.”

To improve the test-reporting process, Ng believes it’s important to consider the following points:

  1. UI specific defects captured should be presented in screenshots through BDD reports, allowing stakeholders to easily see why the functionality has failed in the reports at each test steps
  2. Each ‘scenarios’ in Cucumber Feature files should only test a specific functionality
  3. ‘Background’ in Cucumber Feature files should be used to reduce repetition of steps in test execution and reporting
  4. Cucumber Hooks should be used where possible to create setup and teardown for each test scenarios, this will lead to overall better readability when test reports are produced
  5. Create professional reports by making use of Serenity BDD reporting functionality through the integration of Serenity Rest and Serenity Steps annotations for API tests execution
  6. Test reports should utilise ‘example’ tables where possible to minimise the need for creating duplicate test scenarios for the same types of data sets.

Creating a test framework

When creating a reusable test framework, he also believes that the below practices are the best to consider:

  1. Introduce helper classes, wrapper methods for global functions, and stateless utility methods such as connecting to databases, file loading, test assertions, external libraries, while allowing code reuse for similar sets of functionalities across the framework
  2. Singleton approach provides a global point of access, should ideally be implemented for test logging, as well as test configuration functionality
  3. Use Page Object Model to design a pattern in UI tests in order to reduce test maintenance and the dependency between test code and element locators. This will be a single repository for the services or related operations/functions and provides a great abstraction when implementing step definitions in Cucumber
  4. Stubs and Mocks provide any stubs/mock required for test/execution in lower environments which reduces dependencies on real environments and endpoint; allowing any bugs to be found early on in lower environments.

According to him, it’s also important to follow vendor blogs, articles and webinars such as Blazemeter and Applitools as it can vastly improve knowledge on ensuring tools are fit for purpose, easily accessible and up-to-date.

Written by Leah Alger

More
articles