Python Test Framework for the Technical Task
- Scenario 1 - Playwright + Pytest
- Scenario 2 - Requests + Pytest
- Python v3.10 (or later) installed
pipinstalled (by default)
- Repository has been cloned locally.
- Terminal open in the root of the project.
- Virtual env created with command:
python -m venv .venv
- Activate your virtual environment in the terminal
MacOS or Linux
source .venv/bin/activate
Windows:
.venv\Scripts\activate
- Install dependancies from requirements.txt
pip install -r requirements.txt
- You are now ready to execute the tests
pytest --html=report.html
Currently reporting is created with the pytest-html library as it provides a quick visual report for these tests.
In a more usual setting - I'd prefer to utilise a tool such as Allure. With this tool we can get more in-depth reporting for test methods as allure.steps, for example.
The current automated tests cover the search functionality and suggested results dropdown is showing 5 results.
To go deeper in to the testing of the search functionality, the following could be tested:
- Click each result in the dropdown and verify the search term 'IFRS 17' is contained within the page.
- Press 'Enter' on the search box to verify the same titles and page links are posted on the list page.
Currently the API tests in Scenario 2 (test/test_scenario_2.py) are functional tests, validating some valid / invalid request scenarios and some edge cases.
In a more realistic business situation, the acceptance criteria / requirements of the endpoint would be clearer. Therefore we can create more robust scenarios for better coverage. The test data can also be controlled outside of the test case, if necessary.
Some other approaches to consider:
-
Integration testing - checking the interactions of underlying services are working together.
-
Security testing - we can check for vulnerabilities such as SQL injections, XSS and authentication.
-
Error handling - testing the errors provided are appropriate for the client with the correct status code and to make sure the error message is relevant to the request. Sensitive information shouldn't be exposed in the response message.
-
Performance testing - verify the API can handle higher loads, as well as checking the response time is appropriate for sent requests.
There are more exploratory scenarios we could test of the given API, if we had more information on expected behaviour of the API Client and Server.
Here are some examples:
-
We can test the boundary parameters of the request query.
-
Authentication mechanisms can be verified e.g. is a JWT token required for the endpoint.
-
Response time of each request, under different situations e.g.
- Concurrent request handling of the system
- Varying the size of the payload to see how the API handles the underlying query to the database.
-
Test other methods for the API e.g. GET, DELETE, PUT. Verify the response status code is appropriate to the acceptance criteria.
-
Test the API server under different network conditions (depending on the requirements.)