A lightweight Test Automation Framework (TAF) that blends UI and API testing with Playwright’s power. Built for who like their automation sharp, modular, and fast🚀.
To work with this project, you need to have Node.js
and Yarn
installed. When this project was created, it was developed using:
- Node.js v20.17.0 (LTS)
- Yarn v4.5.0
We recommend using Volta for managing these dependencies. Volta is a hassle-free tool for managing Node.js
versions and associated tools like Yarn
or npm
, ensuring consistent versions across your development environment.
Note: If you already have the correct versions of
Node.js
andYarn
installed, you can skip to the Project Setup section below.
- Automatically switches to the correct
Node.js
andYarn
versions based on the project configuration. - Easy to install and configure.
- Cross-platform support for Windows, macOS, and Linux.
To install Volta
, open your terminal and run:
curl https://get.volta.sh | bash
After installing Volta, you may need to restart your terminal or run the following command to add Volta to your path (if not automatically added):
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
Verifying Your Installation To verify your installation, run:
node -v
yarn -v
Before proceeding, make sure you export the required API credentials for testing. These credentials are the credentials provided by you, necessary for token generation. You need to set the following environment variables in your terminal:
export USER_ID="your_user_id"
export USER_SECRET="your_user_secret"
and replace your_user_id
and your_user_secret
.
NOTE THAT: if you do not export the env variables with the credentials the tests won't run, given that the token is needed for every request!
Once the API credentials are set up, install the project dependencies by running:
yarn install
This will install all project dependencies as specified in the package.json
file.
The project includes a suite of both API and UI tests. Use the following commands to run the tests:
- Run all tests (API + UI):
yarn test
- Run API tests:
yarn test-api
- Run UI tests:
yarn test-ui
After the test execution is completed, Playwright will automatically open the test report in your default browser. If the report does not open automatically, you will see the report URL at the end of the console output. You can manually open this URL in your browser to view the detailed test results. Videos and trace data will only be generated and included in the report for failed tests. This approach helps reduce unnecessary data and keeps the report concise for successful test runs.
This project uses ESLint for linting basic code rules and Prettier for formatting.
- To format the code using Prettier, run:
yarn format
- To lint the code using ESLint, run:
yarn lint
For every TAF I created from scratch I do use Page Object Model to have better organization. This helps in separating test logic from UI actions, making the TAF easier to maintain and extend.
- The
src
folder contains a ui folder to separate from the api stuff, it contains thepage-objects
directory, where pages and components are located. - The
tests
folder also includes a separateui
directory dedicated to test ui specification files only.
An initial exploration run was conducted to familiarize with the application and its elements, then together with the document with the requirements, the main pages and components were identified, and the corresponding elements were extracted.
- Home Page: Defined as
home-page.ts
. - Plans Page: Defined as
plans-page.ts
, containing aplan-details
component.- The
plan-details
component belongs to theplans-page
. - Even though the URL changes when this component is active, it is categorized as a component rather than a page because other plans are still accessible in the DOM. This indicates a modular structure, where the component is a container within the parent page.
- The
The test structure is set up using search-spec.ts
file to describe the main functionalities to be tested.
- A main
test.describe
with a high level test description. - A
test.beforeEach
to handle common prerequisites such as cookie acceptance and notification handling. - A
test
for the specific plan to check with its respectivetest.step
.- A step to Search for a Specific Country.
- A step to Navigate to the First eSIM Plan.
- A final step to Verify Plan Details according to the requirements in the provided document.
The test automation framework is configured to run in full parallelization in the playwright.config.js
file, so the tests needed to be designed also taking that into consideration. For the UI part it is enough avoiding common variables at a higher test.describe level, encapsulating the required objects on each test definition.
Given the multiple elements to validate, a soft assertion strategy is used to validate them without stopping the execution on the first failure.
Elements to verify accuracy, according to the document:
- Title: Moshi Moshi
- Coverage: Japan
- Data: 1 GB
- Validity: 7 days
- Price: $4.50
I decided to trim the leading and trailing white space to assert only the real values.
- Primary Approach: I used Playwright's built-in locator methods
getByTestId
, leveraging the presence ofdata-testid
attributes in almost all the elements. - Fallback Strategy: I used IDs when
data-testid
was not present. - Last Resort: I used class-based selectors when neither of the above options was feasible.
For some time already I have been copying some ideas form the Page Object Model (from the structural point of view), to apply it on the API testing. When you are testing APIs, and even more when you are testing APIs in microservices architectures, there are a bunch of microservices, endpoints and info related to each of them that requires to be organized properly, that is what I called API Objects Model, where all the necessary requests, urls, paths, and any other relevant information for the service is stored in a service-api-object class.
The API part of the TAF is structured as follows:
The src
folder contains a api
folder to separate from the ui
stuff, it contains the api-objects
folder, the fixtures
folder and the api-client.ts
file.
api-objects
folder: is an abstraction layer that helps organize requests to different endpoints in a microservice or monolith architecture.fixtures
folder: Contains all the fixtures required by the tests.api-client.ts
file: Contains the primitive HTTP methods (GET
,POST
, etc.) required for this particular testing process.
api/api-objects/airalo-service.ts
: Following the API Objects principle mentioned above, for this service, all the necessary requests, urls, paths for this particular service are defined within this class. This service class implements theapi/api-client.ts
for all its requests.api/api-client.ts
: It is another abstraction layer that contains the primitive HTTP methods (GET
,POST
, etc.) required for this particular testing process.api/fixtures/base-api-test-fixture.ts
: This fixture helps on authenticating and generating the oauth token for every tests, it extedns thetest
functionality, avoiding steps liketest.beforeEach
.
- Code Reusability: Common API methods (like GET, POST, DELETE) can be reused across multiple service classes, reducing duplication.
- Improved Maintenance: Changes to the HTTP request logic only need to be made in the base
APIClient
rather than in every service class. - Modularity: Organizing endpoints into service classes helps maintain a clean separation between different parts of the API.
- Scalability: Adding new endpoints or services becomes easier due to the structured approach.
The specification file for API tests is similar to the one used for UI testing, but it has some specific configurations for handling API interactions.
- A main
test
for orders/esims creation/verification which is extending fromthe base-api-test-fixture.ts
fixture, and receives theairaloService
andtoken
from it.- A step to Place Order: Executes a POST request to create an order.
- A step to Verify Placed Order: Ensures that the order meets the expected criteria.
- A step to Verify eSIMs Creation: Checks that the eSIMs are correctly generated.
The test automation framework is configured to run in full parallelization in the playwright.config.js
file, so the tests needed to be designed also taking that into consideration. For the API part this was achieved by implementing a base-api-fixture
that performs the authentication process and initialize the AiraloService object using independent context and fresh environment per test, the rest of the objects are encapsulated on each test definition.
According to the provided requirements, the original plan was to:
- Create the order using the
/orders
endpoint. - List created eSIMs using the
/esims
endpoint.
Modified Approach:
- Instead of listing eSIMs directly from the
/sims
endpoint after creating the order, the following sequence was used:- Place the order using the
/orders
endpoint. - Check the order using the
/orders/:id
endpoint to ensure it was created with the specific requirements. - Retrieve eSIMs one by one from the placed order, from the
sims
array when doingGET
/orders/:id
. - Assert Details on each individual eSIM linked to the order using the iccid and the
/sims/:iccd
endpoint, in order to confirm that the details match the original order, instead of getting the 6 latests ones from the whole eSIMS list and retrieving all of them.
- Place the order using the
This approach guarantees a robust validation of the connection between the order and the eSIMs, ensuring data consistency across different endpoints.