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.jsandYarninstalled, you can skip to the Project Setup section below.
- Automatically switches to the correct
Node.jsandYarnversions 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 | bashAfter 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 -vBefore 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 installThis 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-uiAfter 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 lintFor 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
srcfolder contains a ui folder to separate from the api stuff, it contains thepage-objectsdirectory, where pages and components are located. - The
testsfolder also includes a separateuidirectory 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-detailscomponent.- The
plan-detailscomponent 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.describewith a high level test description. - A
test.beforeEachto handle common prerequisites such as cookie acceptance and notification handling. - A
testfor 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-testidattributes in almost all the elements. - Fallback Strategy: I used IDs when
data-testidwas 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-objectsfolder: is an abstraction layer that helps organize requests to different endpoints in a microservice or monolith architecture.fixturesfolder: Contains all the fixtures required by the tests.api-client.tsfile: 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.tsfor 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 thetestfunctionality, 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
APIClientrather 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
testfor orders/esims creation/verification which is extending fromthe base-api-test-fixture.tsfixture, and receives theairaloServiceandtokenfrom 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
/ordersendpoint. - List created eSIMs using the
/esimsendpoint.
Modified Approach:
- Instead of listing eSIMs directly from the
/simsendpoint after creating the order, the following sequence was used:- Place the order using the
/ordersendpoint. - Check the order using the
/orders/:idendpoint to ensure it was created with the specific requirements. - Retrieve eSIMs one by one from the placed order, from the
simsarray when doingGET/orders/:id. - Assert Details on each individual eSIM linked to the order using the iccid and the
/sims/:iccdendpoint, 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.